tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kitching Simon <Simon.Kitch...@orange.ch>
Subject RE: Init params revisited
Date Wed, 13 Sep 2000 07:07:06 GMT
Hi,


> -----Original Message-----
> From:	Stephen Bacon [SMTP:bacon@best.com]
> Sent:	Tuesday, September 12, 2000 11:04 PM
> To:	tomcat-user@jakarta.apache.org
> Subject:	Init params revisited
> 
> 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>
	[Kitching Simon]  
	I am using init-param tags to pass servlet-specific config items, no
problems.

	I believe each init-param tag can hold only one name/value pair, as
you
	will see if you look at the web.dtd file. I presume that because
your
	<init-param> tags are not compliant with the DTD, the XML parser 
	will throw them away. Actually, I would have expected an error
	message about an invalid XML input.....

	The dtd has

	<!ELEMENT init-param (param-name, param-value, description?)>

	ie only one param-name and one param-value tag can be nested,
	with an optional description. compare this with

	<!ELEMENT servlet (icon?, servlet-name, display-name?, description?,
(servlet-class|jsp-file), init
	-param*, load-on-startup?, security-role-ref*)>

	which has "init-param*" - the asterisk indicates multiple
occurrences are allowed.

	try this instead...
	   <servlet>
	     <servlet-name>Test1</servlet-name>
	     <servlet-class>testServlet</servlet-class>
	     <init-param>
	       <param-name>formatopen</param-name>
	       <param-value>XXX</param-value>
	     </init-param>
	     <init-param>
	       <param-name>formatclose</param-name>
	       <param-value>YYY</param-value>
	     </init-param>
	   </servlet>

	[Kitching Simon]  

	Regards,

	Simon 

> 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