Hi all ,
i configured my jdbc drivers and url in Xml but it shows null value

my servlet code

public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
		System.out.println(config.getInitParameter("dbUrl"));
		System.out.println(config.getInitParameter("dbUserName"));
		System.out.println(config.getInitParameter("jdbcDriver"));}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>CMS</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>LoginServlet</servlet-class>
      <init-param>
      <param-name>jdbcDriver</param-name>
      <param-value>com.mysql.jdbc.Driver</param-value>
    </init-param>
    <init-param>
      <param-name>dbURL</param-name>
      <param-value>jdbc:mysql://localhost:3306/invoice</param-value>
    </init-param>
    <init-param>
      <param-name>dbUserName</param-name>
      <param-value>root</param-value>
    </init-param>
    <init-param>
      <param-name>dbPassword</param-name>
      <param-value></param-value>
    </init-param>
  </servlet>   
   <servlet-mapping>
	   <servlet-name>LoginServlet</servlet-name>
	   <url-pattern>/Controller/Login</url-pattern>
   </servlet-mapping>
  
      </web-app>

thanks in advance

Recommended Answers

All 14 Replies

could any one help me

what is it giving a nullpointer on?
if it's on the dbUrl, try with
("dbURL"), since in your call you use lowercase letters, but in your xml uppercases.

thanks for your replay stultuske,
still its not working it shows null value only

could any one help me ....

What's giving null? You don't tell use if you get an error or print statements give null?

print statements displaying null value

Parameter's give result as null, I don't know why.

But if you want, you can connect to your MySQL DB on a java page:
1) Make in your IDE DaoLogin.java
2) Many examples are found online
3) Then in your servlet (For example Servlet.java) make an instance of DaoLogin class
4) After that, call a method from dao class in your servlet to retrieve record data (via SQL query in dao class)

IMPORTANT: This way you use MVC Architecture for your JSP site.

Your Connector configuration will be the same, just store the driver in the appropriate location in your project (in your ide).

Are you confused?

Dear Mike7893,
Thanks for your replay .. I Know MVC architecture when I am doing project Database is not connected properly thats y I tested to print the parameter value from Xml but it shows null value..

what is it giving a nullpointer on?
if it's on the dbUrl, try with
("dbURL"), since in your call you use lowercase letters, but in your xml uppercases.

i am using net beans 6.8 and in that there is no file named web.xml rather it has sun-web.xml, also its content are not same as like in net beans' earlier versions. iit don't have init parameter like and i want to use filter and i have to make changes web.xml but it not work when i make changes own my own in it. why this difference will overcome?

i am using net beans 6.8 and in that there is no file named web.xml rather it has sun-web.xml, also its content are not same as like in net beans' earlier versions. iit don't have init parameter like and i want to use filter and i have to make changes web.xml but it not work when i make changes own my own in it. why this difference will overcome?

That will be down to the fact that you are using NetBeans that is coming with GlassFish as default Java container(server) instead of Tomcat. Take my advise, relay more on knowledge then your IDE.

@anand01 do you think you could create ZIP file of your project and attach it here? If you have git/bitbucket or similar account just post link to source. Also you may want to check your project folder structure and names. (Looks like you reused MVC tutorial in JSP section and made mistake somewhere, otherwise you would be getting these values)

ya peter_budo I am studying with the help of your MVC tutorials only . I tried this before it worked fine, but this time problem in staring stage itself.For my knowledge I project folder structure is correct. I attached that project file too. if you have time help me.
thanks in advance

Sorry for delay.
My MVC tutorial was written long time ago before I become friend with IntelliJ so I did direct development in Tomcat webapps where I created project folder there.

Trying to solve your issue through IDE and folder structure you have, I had to change web.xml servlet-class definition to

<servlet-class>Servlet.LoginServlet</servlet-class>

and removed anotation from LoginServlet

@WebServlet("/Controller/Login")

after that I was able to read data from config. Let me know if you still have some problems. (If I get more time I may try to create this tutorial with Hibernate)

now its working ,
thanks a lot for spending time to solve my issue

if you create tutorial with Hibernate that will be more useful for all, if you think I can do something to create that tutorial I am ready, Thanks once again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.