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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing ServletContext parameters" Watch "accessing ServletContext parameters" New topic
Author

accessing ServletContext parameters

Sarran Vidyakumar
Greenhorn

Joined: Mar 26, 2003
Posts: 28
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

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: http://aspose.com/file-tools
 
subject: accessing ServletContext parameters
 
Similar Threads
JDBC Parameters as Context Parameters?
Rich Faces Calendar
what's the corresponding method for init-param?
Web.config file like
Doubt in ServletContextListener