tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Mapping "/" and *only* "/"
Date Sun, 16 Jul 2000 02:37:42 GMT
Peter Schuller wrote:

> Hello,
>
> What is the correct procedure for mapping "/" (only "/") to a servlet?

There is no mechanism to do this with <servlet-mapping>.  However, if you are
trying to emulate the way that a web server will serve an "index.html" file to
someone who asks for the directory itself, you can use the <welcome-file-list>
to identify the names of welcome files -- typically something like index.jsp --
that is displayed for this purpose.  I haven't ever tried this with a servlet,
but it ought to work.

> With
> the following servlet mapping, *all* requests are mapped to the servlet, and
> I don't know why (since "/*" does that too; why does "/" do the same?):
>

The "/*" and "/" mappings do not quite do the same thing.  The key issue is the
order in which Tomcat, or any servlet container conforming to servlet 2.2, will
try to match your request to a servlet based on the mappings:

1)  Exact match
2)  Longest prefix match against a pattern that ends in "/*"
3)  Extension match (like *.jsp to the JSP servlet)
4)  Default servlet (mapped to "/").

As you can see, the "default servlet" mapping is only used if no other servlet
mapping matches.  If you use a "/*" pattern, that will match everything (except
for exact matches) so that any extension matching you want to do won't happen,
because the "/*" match happens earlier in the priority order.

>
> <servlet-mapping>
>         <servlet-name>
>                 fileviewer
>         </servlet-name>
>         <url-pattern>
>                 /
>         </url-pattern>
> </servlet-mapping>
>

In fact, the "default servlet" in Tomcat 3.1 is the servlet that serves static
resources, which it defines as "anything for which no other servlet or JSP page
matched."

>
> Thanks!
>
> --
> / Peter Schuller, InfiDyne Technologies HB
>

Craig McClanahan



Mime
View raw message