tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carey Parker <>
Subject RE: init parameters and ServletConfig
Date Mon, 29 Oct 2001 17:54:51 GMT
Thanks, Craig - I have a follow-up.

I assume, then, that the engine must somehow provide a different
ServletConfig object for each servlet.  I see no way, given the method calls
below, for the ServletConfig object to know which servlet is invoking it -
so it can't know what to show and what to hide (assuming it has all the
parameters in it).

So, the engine must create a custom ServletConfig object for each servlet
that it calls init() on.  Right?


-----Original Message-----
From: Craig R. McClanahan []
Sent: Monday, October 29, 2001 12:33 PM
To: Tomcat Users List
Subject: Re: init parameters and ServletConfig

On Sat, 27 Oct 2001, Carey Parker wrote:

> Date: Sat, 27 Oct 2001 08:50:41 -0500
> From: Carey Parker <>
> Reply-To: Tomcat Users List <>
> To: "''" <>
> Subject: init parameters and ServletConfig
> I'm creating a simple servlet engine, and I'm confused about which init
> parameters are made available via the ServletConfig object.
> In the DTD for web.xml, there are two sets of parameters: context-param
> init-param.  The context-param's are in the web-app scope and the
> init-params are in the servlet element scope.
> So, when the servlet engine invokes the init() method on the servlet with
> ServletConfig object, and the servlet invokes
> ServletConfig.getParameterNames(), which parameters does it see?
> Let's say we have the following web.xml snippet...
> <web-app>
> <context-param>foo</context-param>
> <servlet>
>    <servlet-name>boo1</servlet-name>
>    <init-param>foo1</init-param>
> </servlet>
> <servlet>
>    <servlet-name>boo2</servlet-name>
>    <init-param>foo2</init-param>
> </servlet>
> </web-app>
> So, there are three parameters here: foo, foo1, and foo2.  When servlet
> does a ServletConfig.getParameterNames(), does it get...
> - just foo1?
> - foo and foo1?
> - foo, foo1 and foo2?

Servlet context parameters (<context-param>) are available to all
servlets, via a call to:

  String value = getServletContext().getInitParameter("foo");

Servlet parameters (<init> inside a <servlet>) are available to that
servlet only, via a call to:

  String value = getServletConfig().getInitParameter("foo1");

(Of course, you have to use the correct syntax in your <init-param>
elements as well :-).

> Thanks!
> Carey


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message