954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Xml Configuration problem

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

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

could any one help me

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

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.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

could any one help me ....

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

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

Mike7893
Newbie Poster
3 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

print statements displaying null value

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

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).

Mike7893
Newbie Poster
3 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

Are you confused?

Mike7893
Newbie Poster
3 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

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..

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 
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?

gourav1
Posting Whiz in Training
203 posts since Oct 2011
Reputation Points: -2
Solved Threads: 2
 
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)

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

Attachments CMS.zip (8.25KB)
anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

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)

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

anand01
Posting Whiz in Training
225 posts since Aug 2010
Reputation Points: 12
Solved Threads: 20
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You