You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Schmitt, Christian" <Ch...@Dresdner-Bank.com> on 2000/08/14 10:37:31 UTC

Servlet mapping

Hi all,
I have a question concerning mapping of servlets.
Consider the following excerpt from server.xml:

<Context 
  path="/cs/maptest" 
  docBase="/home/cs/maptest"
  debug="1"
  reloadable="true" >
</Context>

Now I have the following on my web.xml:
<web-app>
  <servlet>
    <servlet-name>info</servlet-info>
    <servlet-class>Info</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>info</servlet-name>
    <url-pattern>info/*</url-pattern>
  </servlet-mapping>
</web-app>

Now when I point my browser to http://localhost/cs/servlet/info the servlet
is found and executes as expected. But what I really want to do is for
example: http://localhost/cs/some/directory/info but Tomcat does not find
the servlet and returns a 404 error. When I change the servlet mapping in
web.xml to:
  <servlet-mapping>
    <servlet-name>info</servlet-name>
    <url-pattern>/info/*</url-pattern>
  </servlet-mapping>

Now Tomcat finds the servlet under http://localhost/cs/servlet/info as well
as http://localhost/cs/info but not under any other paths.

Am I missing something here or is it not possible?

Thanks for any tips.

Christian Schmitt

Re: Servlet mapping

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Schmitt, Christian" wrote:

> Hi all,
> I have a question concerning mapping of servlets.
> Consider the following excerpt from server.xml:
>
> <Context
>   path="/cs/maptest"
>   docBase="/home/cs/maptest"
>   debug="1"
>   reloadable="true" >
> </Context>
>
> Now I have the following on my web.xml:
> <web-app>
>   <servlet>
>     <servlet-name>info</servlet-info>
>     <servlet-class>Info</servlet-class>
>   </servlet>
>   <servlet-mapping>
>     <servlet-name>info</servlet-name>
>     <url-pattern>info/*</url-pattern>
>   </servlet-mapping>
> </web-app>
>
> Now when I point my browser to http://localhost/cs/servlet/info the servlet
> is found and executes as expected. But what I really want to do is for
> example: http://localhost/cs/some/directory/info but Tomcat does not find
> the servlet and returns a 404 error. When I change the servlet mapping in
> web.xml to:
>   <servlet-mapping>
>     <servlet-name>info</servlet-name>
>     <url-pattern>/info/*</url-pattern>
>   </servlet-mapping>
>
> Now Tomcat finds the servlet under http://localhost/cs/servlet/info as well
> as http://localhost/cs/info but not under any other paths.
>

How about the following (assuming that "/cs" is your context path):

    <servlet-mapping>
        <servlet-name>info</servlet-name>
        <url-pattern>/some/directory/info/*</url-pattern>
    </servlet-mapping>

>
> Am I missing something here or is it not possible?
>
> Thanks for any tips.
>
> Christian Schmitt

Craig