tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Can I start servlets by extension or I need to change web.xml everytime.
Date Sun, 09 Apr 2000 23:39:08 GMT
Peter Schuller wrote:

> > You can try making a generic mapping entry in web.xml
> >
> > <servlet-mapping>
> >       <servlet-name>
> >               whatever
> >       </servlet-name>
> >       <url-pattern>
> >             /whateverdirectory-eg-servlets/*
> >       </url-pattern>
> > </servlet-mapping>
> I'm not the one who asked the original question, but I am having the same
> problem. What exactly should one put there? I've done this:
>         <servlet-mapping>
>             <servlet-name>
>                 invoker
>             </servlet-name>
>             <url-pattern>
>                 *.class
>             </url-pattern>
>         </servlet-mapping>
> But .class files are still treated as static data.

> I'd love to RTFM, but I haven't found any FM yet :) Is there any documentation
> at this point (for Tomcat in general I mean)?

The basic source of information is the Servlet API Specification, version 2.2,
which you can download from <>.
Section 10 talks about how mappings work.

Briefly, you can map a servlet to handle requests of the following types:

- A specific URL path (relative to the context path of your web application).

- A set of URLs that start with a specific prefix (which often looks like a
  directory name when you use it in a URL).

- A filename extension (which is how JSP pages get recognized and
  compiled/executed instead of being displayed.

To illustrate these options, let's assume that you have defined a servlet in your
web application like this:


Now, you let's assume that you have done this in a web application whose context
path is "/myapp", and the complete URL to access this app is:


Now, you might use the following types of mappings:

    <!-- Process http://localhost:8080/myapp/my/exact/path -->

    <!-- Process any URL that starts with
        http://localhost:8080/myapp/images/ -->

    <!-- Process all GIF images myself, instead of
        letting the default file-serving servlet serve them. -->

As the last example illustrates, mapping patterns are case sensitive.

In each case, the servlet container looks at the request URI, figures out which
defined mapping matches (the priority rules are described in the specification),
and therefore identifies the name of the desired servlet.  Next, it loads an
instance of that servlet (if it's not already loaded), and calls your service

For more examples, look at the file "conf/web.xml" under the directory into which
you've loaded Tomcat.  These are the default mappings that are provided for all
web applications, unless you override them.  Note that the "invoker" servlet is
mapped to "/servlet/*", which is why those types of requests work -- the invoker
servlet grabs the servlet class name from the rest of the request, and calls it's
service() method.  In addition, the JSP page compiler servlet is mapped to the
"*.jsp" extension.

> Thank you,
> --
> / Peter Schuller, InfiDyne Technologies HB

Craig McClanahan

View raw message