On Thu, 7 Feb 2002, Russ Trotter wrote:

> Date: Thu, 7 Feb 2002 12:01:01 -0700
> From: Russ Trotter <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED], [EMAIL PROTECTED]
> Subject: Re: servlet-path, path-info and  Filters
>
> First off, changed group "To:" to tomcat-user...
>
> Now to your response:
>
> That's the thing, I have no servlet-mapping (or any servlets defined at all
> for that matter!) in my example.  I'm trying to put a filter on static
> content.  Here's my web.xml
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app
>   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>   "web-app_2_3.dtd">
> <web-app>
>   <filter>
>     <filter-name>testFilter</filter-name>
>     <filter-class>TestFilter</filter-class>
>   </filter>
>   <filter-mapping>
>     <filter-name>testFilter</filter-name>
>     <url-pattern>/files/*</url-pattern>
>   </filter-mapping>
> </web-app>
>
> My "testFilter" does nothing but print the getServletPath() and
> getPathInfo(), then call doFilter() to pass the request down the chain.
>
> If my request is "/context/files/foo.html", Tomcat 4.0.1 says the servlet
> path is "/files/foo.html" and path-info is null.   What am I missing here?
>

But there really *are* mappings here :-).  They are just now in your own
web.xml file.  Look in the "conf/web.xml" file and you will see the global
settings that Tomcat loads for all webapps, before it loads your own.

In particular, what you are seeing is an artifact of how Tomcat has
implemented serving static content.  You will see a <servlet-mapping>
entry for the URL pattern "/", which identifies the default servlet for
this application.  This is the servlet used when no other servlet mapping
is matched.

Tomcat's default servlet (coincidentally named "default") is mapped to
this pattern, and its function is simply to server the specified static
resource.  The servlet spec says that, for the default servlet,
getServletPath() returns the entire request URI after the context path,
and getPathInfo() returns null -- which is precisely what you are seeing.

If, on the other hand, you had one of your own servlets with a
<servlet-mapping> of "/files/*", then you'd have getServletPath()
returning "/files" and getPathInfo() returning "/foo.html".

> thanks,
> russ
>

Craig

> From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
> To: "Tomcat Developers List" <[EMAIL PROTECTED]>
> Sent: Thursday, February 07, 2002 11:02 AM
> Subject: Re: servlet-path, path-info and Filters
>
>
> > > Hello again Craig,
> > >
> > >   Well, after going back into my filter setup again, I see that for
> Tomcat
> > > 4.0.1, i have the same setup that I describe in my example below (e.g. a
> > > url-pattern of "/files/*" for the <filter-mapping> element in web.xml)
> but
> > > the call to getServletPath() inside that filter returns "/files/foo.jpg"
> and
> > > getPathInfo() returns null for a request of "/context/files/foo.jpg".
> > >
> >
> > It's the <servlet-mapping> pattern that drives getServletPath() and
> > getPathInfo(), not the <filter-mapping> pattern.  What's your servlet
> > mapping look like?
> >
> > >   Where's the error? (me, Tomcat, the spec, or all of the above) :-)
> > >
> > > russ
> > >
> >
> > Craig (this is straying into a topic for TOMCAT-USER instead of here ...)
> >
> > >
>
>
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to