tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Bacon <ba...@best.com>
Subject Init params revisited
Date Tue, 12 Sep 2000 21:04:22 GMT
Hello,
   I'm having a problem with initialization parameters, and upon searching 
the last week's digests, came upon a very similar question and solution, 
but it doesn't quite match what I'm trying to do, so if the list doesn't 
mind, I'll ask a very similar q.
I've been running through Sun's "Core Servlets and JavaServer Pages" and 
following its example, tried to use init params. Unfortunately, they're not 
getting retrieved. The web.xml is set up correctly enough so that I can 
access the class via its mapped name "Test1" and not the actual 
servlet-class name, but I'm retrieving NULLs. I'm running Apache 1.3.12 and 
Tomcat 3.1 under RH Linux 6.2
I notice many solutions refer to context params, but I assume init params 
are better to use as they're only for this particular class and not all 
classes in this context.
Any help / pointers appreciated.
-Steve

Here's my web.xml:

<?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>
   <display-name>STB Tests</display-name>
   <description>
     Test application (STB)
   </description>
   <servlet>
     <servlet-name>Test1</servlet-name>
     <servlet-class>testServlet</servlet-class>
     <init-param>
       <param-name>formatopen</param-name>
       <param-value>XXX</param-value>
       <param-name>formatclose</param-name>
       <param-value>YYY</param-value>
     </init-param>
   </servlet>
</web-app>

and here's the init method from my servlet:

   public void init(ServletConfig config)
     throws ServletException {
     // always call super.init
     super.init(config);

     sFormatOpen = config.getInitParameter("formatopen");
     if (sFormatOpen == null) {
       sFormatOpen = "";
       sFormatClose = "";
     }
     else {
       sFormatClose = config.getInitParameter("formatclose");
       if (sFormatClose == null) {
         sFormatOpen = "";
         sFormatClose = "";
       }
     }
   }


Mime
View raw message