This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Init Parameter's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Init Parameter Watch "Servlet Init Parameter New topic
Author

Servlet Init Parameter's

Chad Dalton
Greenhorn

Joined: Feb 19, 2003
Posts: 20
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

Joined: Dec 10, 2003
Posts: 329
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


SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Feb 19, 2003
Posts: 20
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet Init Parameter's