Hi All,
I'm having some problems with
Tomcat 3.2.3.
I am creating a
servlet which uses intialisation parameters called from the init() method in a servlet. I have set up a web.xml file as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
<servlet>
<servlet-name>
ShowMsg
</servlet-name>
<servlet-class>
servlets.ShowMessage
</servlet-class>
<init-param>
<param-name>
message
</param-name>
<param-value>
Dragon!
</param-value>
</init-param>
<init-param>
<param-name>
repeats
</param-name>
<param-value>
5
</param-value>
</init-param>
</servlet>
</web-app>
This is in the directory:
%TOMCAT_HOME%/webapps/root/web-inf/
The class that uses the intialisation paramters is in the directory:
%TOMCAT_HOME%/webapps/root/web-inf/classes/servlets.ShowMessage.java
However, the init method in ShowMessage.java always sets message as null and repeats never gets set.
public void init(ServletConfig config) throws ServletException {
super.init(config);
message = config.getInitParameter("message");
if (message == null) {
message = defaultMessage;
}
try {
String repeatString = config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
} catch(NumberFormatException nfe) {
}
}
I suspect the problem is with my file setup in Tomcat, but I can't figure out what. Should there be a web.xml file in every WEB-INF directory? Do I need to edit server.xml? Any suggestions are appreciated.
Richard Scothern