tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Bergsten <h...@gefionsoftware.com>
Subject Re: Bug in getInitParameter()
Date Tue, 30 May 2000 02:13:24 GMT
Jim Rudnicki wrote:
> 
> I've just bashed up against odd behavior of  getInitParameter().  It seems
> that the canonical name specified in the web.xml must exactly match the
> class name or it does not work. e.g. access
> /myapp/servlet/abc.vault.PostFile
> 
> <servlet>
>   <servlet-name>pfa</servlet-name>
>   <servlet-class>abc.vault.PostFile</servlet-class>
> 
> does not result in getInitParameter() returning values.  Oddly add a
> mapping:
> 
> <servlet-mapping>
>    <servlet-name>pfa</servlet-name>
>    <url-pattern>/pfile</url-pattern>
> 
> and the same servlet does get the init parameters only when accessed thru
> the mapped url: /myapp/pfile
> 
> If I change the canonical to match the fully qualified class name:
> 
> <servlet>
>   <servlet-name>abc.vault.PostFile</servlet-name>
>   <servlet-class>abc.vault.PostFile</servlet-class>
> 
> then /myapp/servlet/abc.vault.PostFile does get the init parameters, and the
> mapped url also does.
> 
> Odd?

It's not so odd ;-) The <servlet> element lets you configure a named
instance of a servlet class and specify init parameters. In order for
your servlet to see these parameters, you must invoke the named 
instance, i.e. with a URL like /myapp/servlet/pfa in your example. 
You can define multiple named instances of the same servlet class
with different init parameters (and names, obviously).

When you use a URL like /myapp/servlet/abc.vault.PostFile you ask the 
invoker to call an unnamed instance of your servlet. That's why you
do not get the parameters. When you added the mapping, you mapped it
to the named instance. Hence it worked.

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com

Mime
View raw message