This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
<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
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