tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Trasuk" <stratus...@on.aibn.com>
Subject RE: InitParameters missing in ServletConfig when Servlet-loading triggerd through RequestDispatcher
Date Thu, 16 May 2002 14:43:13 GMT
	What you'll probably find is that even though you can get the
servlet's init() method to print out its parameters, when you actually
invoke the servlet through /servlet/classname, you are invoking another
instance of the servlet class that is not initialized with your parameters.
All you're doing by loading it at startup is creating a named instance of
the servlet, but not mapping any requests to it.

	Using the "/servlet/classname" form of invoking the servlet causes
the default servlet invoker (another servlet) to be used.  The servlet
invoker typically doesn't have init parameters in it.  In order for your
servlet to be initialized, you need to declare it in web.xml AND map the url
to it using a url-mapping element.  For example,

    <servlet>
        <servlet-name>
            CompressionFilterTestServlet
        </servlet-name>
        <servlet-class>
            compressionFilters.CompressionFilterTestServlet
        </servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>
            CompressionFilterTestServlet
        </servlet-name>
        <url-pattern>
            /CompressionTest
        </url-pattern>
    </servlet-mapping>


	It's actually bad form to use the "/servlet/classname" invoker to
call a servlet, since the presence of the invoker is not guaranteed by the
servlet spec.

	You can also forward to the servlet by using the name declared in
the <servlet-name> element, without mapping the servlet to a URL.  This has
the advantage of hiding the existence of the target servlet.

Cheers,



Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.
http://stratuscom.ca

> -----Original Message-----
> From: Philipp von Hartrott [mailto:p.hartrott@datadesignag.com]
> Sent: May 16, 2002 09:40
> To: Tomcat Users List
> Subject: InitParameters missing in ServletConfig when Servlet-loading
> triggerd through RequestDispatcher
> 
> 
> Hello,
> using Tomcat 4.0.3 (and 4.0.2 also) I encounter the following problem:
> 
> Problem setup:
> My servlet has no <load-on-startup/> set.
> 
> I start Tomcat.
> I trigger the loading of servlet A through a 
> RequestDispatchers forward as quoted below.
> I trace my servlet A's ServletConfig init-parameters in the 
> init() method call.
> The newly loaded servlet A's ServletConfig DOES NOT contain 
> the init-parameters I specifed in web.xml!
> 
> Unsatisfying solution setup:
> This time I specify a <load-on-startup>1</load-on-startup> in web.xml:
> 
> I start Tomcat.
> The loading of servlet A is triggerd through the container on startup.
> I trace my servlet A's ServletConfig init-parameters in the 
> init() method call.
> The newly loaded servlet A's ServletConfig as expected DOES 
> contain all init-parameters I specifed in web.xml.
> 
> Why are my init-parameters missing in the first case?
> 
> Thank you,
> Philipp.
> 
> 
> Code used for forwarding:
> RequestDispatcher requestDispatcher = 
> getServletContext().getRequestDispatcher("/servlet/" + 
> responsibleServletName);
> requestDispatcher.forward(servletRequest, servletResponse);
> 
> --
> To unsubscribe, e-mail:   
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>

Mime
View raw message