Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Init Parameter's

 
Chad Dalton
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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).
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • 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
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic