File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
I agree. Here's the link:
subject: accessing ServletContext parameters
It's not a secret anymore!