• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

accessing ServletContext parameters

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic