Hello,
 
I'm having problems in my application that implies Tomcat and servlets.
 
In one of my  servlets, i have programmed the init(ServletConfig sc) method to get parameters that i have initialized in the web.xml configuration file of my application, as i have seen on different examples on the web.
 
servlet code:
 
public class Servlet1 extends HttpServlet {
 
public void init(ServletConfig sc) throws ServletException {
 super.init(sc);
 String myParam = sc.getInitParameter("PARAM");
}
.....
 
/.../jakarta-tomcat/webapps/myApp/WEB-INF/server.xml code:
 
<?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>myServlet</servlet-name>
      <servlet-class>Servlet1</servlet-class>
      <init-param>
         <param-name>PARAM</param-name>
         <param-value>hello</param-value>
      </init-param>
   </servlet>
   <servlet-mapping>
      <servlet-name>myServlet</servlet-name>
      <url-pattern>/Servlet1</url-pattern>
   </servlet-mapping>
</web-app>
 
I have also defined the servlet context of the application (/MyApp) in the server.xml file.
 
But when i try to reach the URL http://<tomcat host>:8080/MyApp/servlet/Servlet1
I get "null" instead of "hello" as the value of the init parameter "PARAM" when i try to get it.
 
Can someone tell me why, and what is the good way to initialize servlet parameters censed to be retrieved by the ServletConfig.getInitParameter() method ? is it really the web.xml file that does the job ? if yes, is it necessary to configure Tomcat a special way for that (which way ?), and could you write me down a short example ?
 
I have programmed another servlet (servlet2) that doesn't parse any init parameters, and when i reach the URL http://<tomcat host>:8080/MyApp/servlet/Servlet2, the result of the execution of the servlet is OK.
 
St�phane
 

Reply via email to