aspose file tools
The moose likes Servlets and the fly likes accessing ServletContext parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing ServletContext parameters" Watch "accessing ServletContext parameters" New topic

accessing ServletContext parameters

Sarran Vidyakumar

Joined: Mar 26, 2003
Posts: 28
Need help with the following problem..

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) ???
Steve Roderick

Joined: Mar 15, 2003
Posts: 5
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
jQuery in Action, 2nd edition
subject: accessing ServletContext parameters