• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Init Parameter's

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet that loads on startup (<load-on-startup>1</load-on-startup> . It takes 1 parameter, a boot.properties file name. It's the name of a file on the file system that contains a list of properties for the servlet. When I start the server I see that the servlet reads the init-parameter name/value pair correctly and reads the properties file and populates the member variables of the servlet. However, when I navigate to the servlet the init is called again and this time the properties filename is empty so it fails on unable to open null. How can I configure it so the value in web.xml will be used for every instance of the servlet? I would like NOT to make it a context level parameter.
thanks,
Server: Tomcat 4.1.27, JDK 1.3 (unable to upgrade, being hosted).
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In previous project I had property file on server (contains database URL & Password etc..) I was retrieving values from file using following code.

What you are doing is put file name in servlet init parameter like this
<servlet>
<init-param>
<param-name>filename</param-name>
<param-value>"<actual nameof file>"</param-value>
</init-param>
</sevlet>
Now in your init you get just name of file & read it anywhere else.
Hope I understand & this help.
SCJP 1.4
SCWCD
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I vaguely recall that init() being run twice on the same servlet was the result of "invoker servlet" evilness.

Are you calling the servlet through a path like: "/servlet/foo" ?
 
Chad Dalton
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Curwen:

Are you calling the servlet through a path like: "/servlet/foo" ?


Yes, and that was partically my problem. In the <name> portion of the <servlet> parmeter of my web.xml I had servlet.com.my.servlet.name, once I woke up and removed the servlet. part everything worked fine .
thanks,
--chad
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic