I'm new to this list, so please forgive me if this question has been raised
before....
I'm running Tomcat 3.2.1, Apache 1.3.12, java 1.2.2 and Redhat 6.2.
I have a servlet to which I want to pass a single parameter via the web.xml
file (below). I'm obtaining the parameter value by calling
config.getInitParameter() in the init method of the servlet.
This seems to work fine, the init method is called and the value obtained OK
when Tomcat is started.
The problem is that when the first request for the servlet arrives, the init
method is run A SECOND TIME. This time the init parameter IS NOT AVAILABLE.
My theory is that Tomcat calls the init method once for each thread, but if
that is true, I would expect Tomcat to pass the init parameters each time?
What is wrong?
BTW, I can't get the servlet-mapping to work either. Any obvious errors?
Thanks,
Hans J. Helgesen
Here is my web.xml file:
------------------------
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>My test application</display-name>
<description>
Description of my test application
</description>
<servlet>
<servlet-name>MyServlet</servlet-name>
<description>
Description of my servlet
</description>
<servlet-class>no.fellesdata.MyServlet</servlet-class>
<init-param>
<param-name>ConfigFile</param-name>
<param-value>/usr/local/jakarta-tomcat/webapps/poes/WEB-INF/myservlet.config
</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>
And here is part of my servlet code:
------------------------------------
public void init (ServletConfig config) throws ServletException
{
super.init(config);
....bla-bla-bla.....
// Load configfile if it exists.
configfile = config.getInitParameter("ConfigFile");
if (null == configfile) {
configfile = "default.value";
}
}