You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by John Hawkins <ha...@btconnect.com> on 2007/01/31 22:09:06 UTC

Servlet init params not being picked up

Hi,

My servlet isn't picking up the init params. Am I doing something wrong?

Additionally - can I change these params in the geronimo-web.xml file so they change at deployment?

My servlet init method

public void init() throws ServletException
{
super.init();
// I used to get a specific param but that failed too so I moved to this test case
Enumeration names = getServletContext().getInitParameterNames();
System.out.println("Printing out init params");
while(names.hasMoreElements())
{
System.out.println("'"+names.nextElement()+"'");
}

outputs this to stdio ->
Printing out init params

but no params !

This is the web.xml....

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>my servlet</display-name>
<description>Test servlet</description>
<distributable> </distributable>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>mytest.MyServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>myParam</param-name>
<param-value>myParamValue</param-value>
</init-param>
</servlet>
</web-app>

Here's my geronimo-web.xml....

<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>mygroup</dep:groupId>
<dep:artifactId>myartifactID</dep:artifactId>
<dep:type>war</dep:type>
</dep:moduleId>
<dep:dependencies />
<dep:hidden-classes />
<dep:non-overridable-classes />
</dep:environment>
<context-root>/mycontextroot</context-root>
</web-app>

Re: Servlet init params not being picked up

Posted by David Jencks <da...@yahoo.com>.
On Feb 1, 2007, at 2:18 AM, John Hawkins wrote:

>
> Ah - that did it - thankyou !
>
> This works in other servers - is this a "feature"?

Not sure....I thought we were relying on the jetty and tomcat  
behavior here rather than trying to override it.
>
>
> Any clue if I can override the servlet params in my geronimo- 
> web.xml file?

Not yet :-).  This sounds like a good feature request though.

thanks
david jencks

>
>
> many thanks,
> John.
>
>
>
>
> -----Original Message-----
> From: David Carew [mailto:dccarew@gmail.com]
> Sent: Thu 01/02/2007 01:02
> To: user@geronimo.apache.org
> Subject: Re: Servlet init params not being picked up
>
> I don't think the init parameters are available via the method  
> you're using
> until after  the servlet is initialized. Try using this signature  
> for init
>
> public void init(ServletConfig config) throws ServletException
>
> and then using the getParameterNames method on the ServletConfig  
> object.
>
>
>
> On 1/31/07, John Hawkins <ha...@btconnect.com> wrote:
>>
>> Hi,
>>
>> My servlet isn't picking up the init params. Am I doing something  
>> wrong?
>>
>> Additionally - can I change these params in the geronimo-web.xml  
>> file so
>> they change at deployment?
>>
>> My servlet init method
>>
>> public void init() throws ServletException
>> {
>> super.init();
>> // I used to get a specific param but that failed too so I moved  
>> to this
>> test case
>> Enumeration names = getServletContext().getInitParameterNames();
>> System.out.println("Printing out init params");
>> while(names.hasMoreElements())
>> {
>> System.out.println("'"+names.nextElement()+"'");
>> }
>>
>> outputs this to stdio ->
>> Printing out init params
>>
>> but no params !
>>
>> This is the web.xml....
>>
>> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web  
>> Application
>> 2.3//EN"
>> "http://java.sun.com/dtd/web-app_2_3.dtd">
>>
>> <web-app>
>> <display-name>my servlet</display-name>
>> <description>Test servlet</description>
>> <distributable> </distributable>
>> <servlet>
>> <servlet-name>TestServlet</servlet-name>
>> <servlet-class>mytest.MyServlet</servlet-class>
>> <init-param>
>> <description>
>> </description>
>> <param-name>myParam</param-name>
>> <param-value>myParamValue</param-value>
>> </init-param>
>> </servlet>
>> </web-app>
>>
>> Here's my geronimo-web.xml....
>>
>> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/ 
>> tomcat-1.1">
>> <dep:environment xmlns:dep="
>> http://geronimo.apache.org/xml/ns/deployment-1.1">
>> <dep:moduleId>
>> <dep:groupId>mygroup</dep:groupId>
>> <dep:artifactId>myartifactID</dep:artifactId>
>> <dep:type>war</dep:type>
>> </dep:moduleId>
>> <dep:dependencies />
>> <dep:hidden-classes />
>> <dep:non-overridable-classes />
>> </dep:environment>
>> <context-root>/mycontextroot</context-root>
>> </web-app>
>>
>
> <winmail.dat>


Re: Servlet init params not being picked up

Posted by David Carew <dc...@gmail.com>.
I think this might be a grey area in the spec.AFAIK it doesn't actually say
that the ServletContext needs to be have the init params  before the call to
the  init method completes. So some  implementations might do that post init
and others might do it pre init.

On 2/1/07, John Hawkins <ha...@btconnect.com> wrote:
>
>
> Ah - that did it - thankyou !
>
> This works in other servers - is this a "feature"?
>
>
> Any clue if I can override the servlet params in my geronimo-web.xml file?
>
>
> many thanks,
> John.
>
>
>
>
> -----Original Message-----
> From: David Carew [mailto:dccarew@gmail.com]
> Sent: Thu 01/02/2007 01:02
> To: user@geronimo.apache.org
> Subject: Re: Servlet init params not being picked up
>
> I don't think the init parameters are available via the method you're
> using
> until after  the servlet is initialized. Try using this signature for init
>
> public void init(ServletConfig config) throws ServletException
>
> and then using the getParameterNames method on the ServletConfig object.
>
>
>
> On 1/31/07, John Hawkins <ha...@btconnect.com> wrote:
> >
> > Hi,
> >
> > My servlet isn't picking up the init params. Am I doing something wrong?
> >
> > Additionally - can I change these params in the geronimo-web.xml file so
> > they change at deployment?
> >
> > My servlet init method
> >
> > public void init() throws ServletException
> > {
> > super.init();
> > // I used to get a specific param but that failed too so I moved to this
> > test case
> > Enumeration names = getServletContext().getInitParameterNames();
> > System.out.println("Printing out init params");
> > while(names.hasMoreElements())
> > {
> > System.out.println("'"+names.nextElement()+"'");
> > }
> >
> > outputs this to stdio ->
> > Printing out init params
> >
> > but no params !
> >
> > This is the web.xml....
> >
> > <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
> > 2.3//EN"
> > "http://java.sun.com/dtd/web-app_2_3.dtd">
> >
> > <web-app>
> > <display-name>my servlet</display-name>
> > <description>Test servlet</description>
> > <distributable> </distributable>
> > <servlet>
> > <servlet-name>TestServlet</servlet-name>
> > <servlet-class>mytest.MyServlet</servlet-class>
> > <init-param>
> > <description>
> > </description>
> > <param-name>myParam</param-name>
> > <param-value>myParamValue</param-value>
> > </init-param>
> > </servlet>
> > </web-app>
> >
> > Here's my geronimo-web.xml....
> >
> > <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1">
> > <dep:environment xmlns:dep="
> > http://geronimo.apache.org/xml/ns/deployment-1.1">
> > <dep:moduleId>
> > <dep:groupId>mygroup</dep:groupId>
> > <dep:artifactId>myartifactID</dep:artifactId>
> > <dep:type>war</dep:type>
> > </dep:moduleId>
> > <dep:dependencies />
> > <dep:hidden-classes />
> > <dep:non-overridable-classes />
> > </dep:environment>
> > <context-root>/mycontextroot</context-root>
> > </web-app>
> >
>
>
>

RE: Servlet init params not being picked up

Posted by John Hawkins <ha...@btconnect.com>.
Ah - that did it - thankyou !

This works in other servers - is this a "feature"?


Any clue if I can override the servlet params in my geronimo-web.xml file?


many thanks,
John.




-----Original Message-----
From: David Carew [mailto:dccarew@gmail.com]
Sent: Thu 01/02/2007 01:02
To: user@geronimo.apache.org
Subject: Re: Servlet init params not being picked up
 
I don't think the init parameters are available via the method you're using
until after  the servlet is initialized. Try using this signature for init

public void init(ServletConfig config) throws ServletException

and then using the getParameterNames method on the ServletConfig object.



On 1/31/07, John Hawkins <ha...@btconnect.com> wrote:
>
> Hi,
>
> My servlet isn't picking up the init params. Am I doing something wrong?
>
> Additionally - can I change these params in the geronimo-web.xml file so
> they change at deployment?
>
> My servlet init method
>
> public void init() throws ServletException
> {
> super.init();
> // I used to get a specific param but that failed too so I moved to this
> test case
> Enumeration names = getServletContext().getInitParameterNames();
> System.out.println("Printing out init params");
> while(names.hasMoreElements())
> {
> System.out.println("'"+names.nextElement()+"'");
> }
>
> outputs this to stdio ->
> Printing out init params
>
> but no params !
>
> This is the web.xml....
>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
> 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
> <display-name>my servlet</display-name>
> <description>Test servlet</description>
> <distributable> </distributable>
> <servlet>
> <servlet-name>TestServlet</servlet-name>
> <servlet-class>mytest.MyServlet</servlet-class>
> <init-param>
> <description>
> </description>
> <param-name>myParam</param-name>
> <param-value>myParamValue</param-value>
> </init-param>
> </servlet>
> </web-app>
>
> Here's my geronimo-web.xml....
>
> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1">
> <dep:environment xmlns:dep="
> http://geronimo.apache.org/xml/ns/deployment-1.1">
> <dep:moduleId>
> <dep:groupId>mygroup</dep:groupId>
> <dep:artifactId>myartifactID</dep:artifactId>
> <dep:type>war</dep:type>
> </dep:moduleId>
> <dep:dependencies />
> <dep:hidden-classes />
> <dep:non-overridable-classes />
> </dep:environment>
> <context-root>/mycontextroot</context-root>
> </web-app>
>


Re: Servlet init params not being picked up

Posted by David Carew <dc...@gmail.com>.
I don't think the init parameters are available via the method you're using
until after  the servlet is initialized. Try using this signature for init

public void init(ServletConfig config) throws ServletException

and then using the getParameterNames method on the ServletConfig object.



On 1/31/07, John Hawkins <ha...@btconnect.com> wrote:
>
> Hi,
>
> My servlet isn't picking up the init params. Am I doing something wrong?
>
> Additionally - can I change these params in the geronimo-web.xml file so
> they change at deployment?
>
> My servlet init method
>
> public void init() throws ServletException
> {
> super.init();
> // I used to get a specific param but that failed too so I moved to this
> test case
> Enumeration names = getServletContext().getInitParameterNames();
> System.out.println("Printing out init params");
> while(names.hasMoreElements())
> {
> System.out.println("'"+names.nextElement()+"'");
> }
>
> outputs this to stdio ->
> Printing out init params
>
> but no params !
>
> This is the web.xml....
>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
> 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
> <display-name>my servlet</display-name>
> <description>Test servlet</description>
> <distributable> </distributable>
> <servlet>
> <servlet-name>TestServlet</servlet-name>
> <servlet-class>mytest.MyServlet</servlet-class>
> <init-param>
> <description>
> </description>
> <param-name>myParam</param-name>
> <param-value>myParamValue</param-value>
> </init-param>
> </servlet>
> </web-app>
>
> Here's my geronimo-web.xml....
>
> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1">
> <dep:environment xmlns:dep="
> http://geronimo.apache.org/xml/ns/deployment-1.1">
> <dep:moduleId>
> <dep:groupId>mygroup</dep:groupId>
> <dep:artifactId>myartifactID</dep:artifactId>
> <dep:type>war</dep:type>
> </dep:moduleId>
> <dep:dependencies />
> <dep:hidden-classes />
> <dep:non-overridable-classes />
> </dep:environment>
> <context-root>/mycontextroot</context-root>
> </web-app>
>