You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Marek, Tomas" <Ma...@gedas.cz> on 2002/06/07 16:04:17 UTC

Problem With Params In Web.xml

Guys,
 
could anybody help, please? Having a servlet reading parameters in init()
method but it reads nothing. The servlet is in path
install_dir/webapps/ROOT/WEB-INF/classes/examples and web.xml is in path
install_dir/webapps/ROOT/WEB-INF.
The content of web.xml looks like the following:
 
<?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>
  <servlet>
    <servlet-name>
      ShowMsg
    </servlet-name>
 
    <servlet-class>
      examples.ShowMessage
    </servlet-class>
 
    <init-param>
      <param-name>
        message
      </param-name>
      <param-value>
        blablabla
      </param-value>
    </init-param>
 
    <init-param>
      <param-name>
        repeats
      </param-name>
      <param-value>
        5
      </param-value>
    </init-param>
  </servlet>
</web-app>
 
Does anybody have an idea where's the problem? Thanks in advance for any
clue.
 
tom

RE: Problem With Params In Web.xml

Posted by Greg Trasuk <st...@on.aibn.com>.
Tomas:

        How are you invoking the servlet?  If you don't have a
<servlet-mapping> element in your web.xml (I don't see one in what you
posted, but I realize you might have posted an extract) and you're accessing
it using something like
http://localhost:8080/App/servlet/examples.ShowMessage, then the servlet
won't read the initialization parameters you've set.

        Why? Because when you use the .../servlet/class.name form, you're
actually using the "invoker" servlet that is provided by default.  See the
following in Tomcat's default web.xml (located in $CATALINA_HOME/conf):

  <servlet>
    <servlet-name>invoker</servlet-name>

<servlet-class>org.apache.catalina.servlets.InvokerServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>0</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

        ... other sections not shown ...

  <!-- The mapping for the invoker servlet -->
  <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
  </servlet-mapping>

        What's happening is that when the url includes '/servlet', the
request gets passed to the invoker servlet, which simply creates an instance
of your servlet class and calls its init() and service() methods without any
initialization parameters.  You need to put your own <servlet-mapping>
method into the web.xml, which calls out your servlet class and your url
pattern.  Then the init paramters will be available to you.

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: Marek, Tomas [mailto:MarekT@gedas.cz]
> Sent: June 07, 2002 10:04
> To: tomcat-user@jakarta.apache.org
> Subject: Problem With Params In Web.xml
>
>
> Guys,
>
> could anybody help, please? Having a servlet reading
> parameters in init()
> method but it reads nothing. The servlet is in path
> install_dir/webapps/ROOT/WEB-INF/classes/examples and web.xml
> is in path
> install_dir/webapps/ROOT/WEB-INF.
> The content of web.xml looks like the following:
>
> <?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>
>   <servlet>
>     <servlet-name>
>       ShowMsg
>     </servlet-name>
>
>     <servlet-class>
>       examples.ShowMessage
>     </servlet-class>
>
>     <init-param>
>       <param-name>
>         message
>       </param-name>
>       <param-value>
>         blablabla
>       </param-value>
>     </init-param>
>
>     <init-param>
>       <param-name>
>         repeats
>       </param-name>
>       <param-value>
>         5
>       </param-value>
>     </init-param>
>   </servlet>
> </web-app>
>
> Does anybody have an idea where's the problem? Thanks in
> advance for any
> clue.
>
> tom
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Problem With Params In Web.xml

Posted by Aline <al...@webcaster.fr>.
Hi,

Try to init your parameters like yhis :

<web-app>
	<context-param>
		<param-name>configFile</param-name>
		<param-value>/WEB-INF/conf.xml</param-value>
		<description>path ...</description>
	</context-param>

	<servlet>
		<servlet-name>myServlet</servlet-name>
		<servlet-class>MyServlet</servlet-class>
	</servlet>
</web-app>

And to :
getServletContext().getInitParameter("configFile") in your servlet.

Aline
Webcaster 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>