Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Doubt in ServletContextListener

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am developing a web app where I am using mysql as a database.
Now I want to build the db connection String using the parameter defined in the <context-param> tag of <web-app>
Here is my context param which I have put under <web-app> tag.


<context-param>

<param-name>serverName</param-name>
<param-value>localhost</param-value>


<param-name>dbName</param-name>
<param-value>testDataBase</param-value>

<param-name>userName</param-name>
<param-value>user1</param-value>

<param-name>password</param-name>
<param-value>password1234 </param-value>
</context-param>

Now when I try to access these parameters for eg: serverName using following code.

ServletContext sc = event.getServletContext();
String serverName = "";
serverName = sc.getInitParameter("serverName");


I am getting the value of serverName as null.


can anyone help me in this regard?

Thanks in advance
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you properly form your xml?

It should be something like this:



Although, I am thinking, you shouldnt be able to deploy it if the xml was wrong.
[ January 13, 2007: Message edited by: Jesus Angeles ]
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just check your DD , whether it is having the proper entry for
<listener-class> tag, the class which is implementing ServletContextListener.
 
Suchen Chodankar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys...

It's working now ...

To
Neetika Sood

<listener-class> tag and the class which is implementing ServletContextListene was proper but the problem was in the <context-param> block.
Then I reformatted my Context param to something like this.

<context-param>
<param-name>serverName</param-name>
<param-value>localhost</param-value>
</context-param>


<context-param>
<param-name>dbName</param-name>
<param-value>testDataBase</param-value>
</context-param>

and it worked.


Although, I am thinking, you shouldnt be able to deploy it if the xml was wrong.




To,
Jesus Angeles

With the previous style which is there in my question that is putting multiple <param-name>,<param-value> pairs in single <context-param> I was able to deploy my application without any error mesaage.


So from this I can say that if you want more than one context-params you cannot put all of them in a single <context-param> block.


Thanks once again.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for sharing. Now, I am wondering why it was successfully deployed.
 
reply
    Bookmark Topic Watch Topic
  • New Topic