• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing ServletContext parameters

 
Sarran Vidyakumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help with the following problem..

<context-param>
<param-name>dBinfo</param-name>
<paramvalue>jdbc:microsoft:sqlserver://10.29.9.44:1433;DatabaseName=usrmgt</param-value>
</context-param>
I am able to access the dBinfo value in servlets/jsp using
ServletContext servletContext = this.getServletContext();
String value = servletContext.getInitParameter("dBinfo")
Question is how can I access dBinfo in a java class under webapp(not a servlet) ???
Thanks
 
Steve Roderick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't believe you can .... unless you pass in the servletcontext object as a parameter to the class constructor.
What I have done in a similar situation is to use the servlet listener interfaces to create a database connection when the servlet is initialized and pass that to the helper classes instead. You can also use them to close the connection when the servlet context is destroyed.
Hope that helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic