You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Russ Trotter <ru...@yahoo.com> on 2002/02/07 07:04:40 UTC

servlet-path, path-info and Filters

Does anyone here know what the official correct handling of
ServletRequest.getServletPath() and ServletRequest.getPathInfo() should be?
More specifically, if I specify a filter with an url-pattern of "/files/*"
and I make a request to "/context/files/foo.jpg", what should
getServletPath() and getPathInfo() return?

I've observed some differing behavior between Tomcat 4.0.1 and Jetty in this
regard and the spec doesn't explicitly clear up the issue between the two.

Thanks,
russ


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


Re: servlet-path, path-info and Filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 7 Feb 2002, Russ Trotter wrote:

> Date: Thu, 7 Feb 2002 12:01:01 -0700
> From: Russ Trotter <ru...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org, craigmcc@apache.org
> 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" <cr...@apache.org>
> To: "Tomcat Developers List" <to...@jakarta.apache.org>
> 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:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: servlet-path, path-info and Filters

Posted by Russ Trotter <ru...@yahoo.com>.
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?

thanks,
russ





----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
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:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: servlet-path, path-info and Filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 7 Feb 2002, Russ Trotter wrote:

> Date: Thu, 7 Feb 2002 10:42:11 -0700
> From: Russ Trotter <ru...@yahoo.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> 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 ...)

>
> ----- Original Message -----
> From: "Craig R. McClanahan" <cr...@apache.org>
> To: "Tomcat Developers List" <to...@jakarta.apache.org>
> Sent: Thursday, February 07, 2002 9:09 AM
> Subject: Re: servlet-path, path-info and Filters
>
>
> >
> >
> > On Wed, 6 Feb 2002, Russ Trotter wrote:
> >
> > > Date: Wed, 6 Feb 2002 23:04:40 -0700
> > > From: Russ Trotter <ru...@yahoo.com>
> > > Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> > > To: Tomcat Developers List <to...@jakarta.apache.org>
> > > Subject: servlet-path, path-info and  Filters
> > >
> > > Does anyone here know what the official correct handling of
> > > ServletRequest.getServletPath() and ServletRequest.getPathInfo() should
> be?
> > > More specifically, if I specify a filter with an url-pattern of
> "/files/*"
> > > and I make a request to "/context/files/foo.jpg", what should
> > > getServletPath() and getPathInfo() return?
> > >
> > > I've observed some differing behavior between Tomcat 4.0.1 and Jetty in
> this
> > > regard and the spec doesn't explicitly clear up the issue between the
> two.
> > >
> >
> > The rules are in the Servlet 2.3 Specification, section 11.  In your
> > particular example, getServletPath will return "/files" and getPathInfo()
> > will return "/foo.jpg".
> >
> > > Thanks,
> > > russ
> > >
> >
> > Craig
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


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


Re: servlet-path, path-info and Filters

Posted by Russ Trotter <ru...@yahoo.com>.
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".

  Where's the error? (me, Tomcat, the spec, or all of the above) :-)

russ


----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Thursday, February 07, 2002 9:09 AM
Subject: Re: servlet-path, path-info and Filters


>
>
> On Wed, 6 Feb 2002, Russ Trotter wrote:
>
> > Date: Wed, 6 Feb 2002 23:04:40 -0700
> > From: Russ Trotter <ru...@yahoo.com>
> > Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> > To: Tomcat Developers List <to...@jakarta.apache.org>
> > Subject: servlet-path, path-info and  Filters
> >
> > Does anyone here know what the official correct handling of
> > ServletRequest.getServletPath() and ServletRequest.getPathInfo() should
be?
> > More specifically, if I specify a filter with an url-pattern of
"/files/*"
> > and I make a request to "/context/files/foo.jpg", what should
> > getServletPath() and getPathInfo() return?
> >
> > I've observed some differing behavior between Tomcat 4.0.1 and Jetty in
this
> > regard and the spec doesn't explicitly clear up the issue between the
two.
> >
>
> The rules are in the Servlet 2.3 Specification, section 11.  In your
> particular example, getServletPath will return "/files" and getPathInfo()
> will return "/foo.jpg".
>
> > Thanks,
> > russ
> >
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


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


Re: servlet-path, path-info and Filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 7 Feb 2002, Russ Trotter wrote:

> Date: Thu, 7 Feb 2002 10:22:56 -0700
> From: Russ Trotter <ru...@yahoo.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: Re: servlet-path, path-info and  Filters
>
> Thank for your response Craig.
>
> Just re-read SRV.11 (for the umpteenth time!)
>
> So just so I have understanding, whatever resource (either static file,
> servlet, etc) the filter is filtering is irrelavent in determining what is
> returned from getServletPath(), getPathInfo() _in the filter_?
>

Well, mostly ...

I think the most you can say is that what the *first* filter in the chain
sees is what's defined by the servlet spec -- the same thing that the
servlet would see if there were no filters.  However, you're at the mercy
of request wrappers that might have been installed by an earlier filter in
the chain for what you really see.

The servlet spec rules only describe what Tomcat will hand to the first
application component that processes the request.

> >From what you're saying whether it's a filter or a servlet, if the
> url-pattern is "/something/*" then that is the return of the
> getServletPath() call?  Both being consistent with one-another?
>

Yes.  The URL pattern that was matched to select a filter does not affect
the values returned by getServletPath() or getPathInfo() -- which is a
good thing, because different filter mapping patterns could both apply to
the same request and there wouldn't be any way to tell them apart.

> thanks again,
> russ
>

Craig


>
> ----- Original Message -----
> From: "Craig R. McClanahan" <cr...@apache.org>
> To: "Tomcat Developers List" <to...@jakarta.apache.org>
> Sent: Thursday, February 07, 2002 9:09 AM
> Subject: Re: servlet-path, path-info and Filters
>
>
> >
> >
> >
> > The rules are in the Servlet 2.3 Specification, section 11.  In your
> > particular example, getServletPath will return "/files" and getPathInfo()
> > will return "/foo.jpg".
> >
> > > Thanks,
> > > russ
> > >
> >
> > Craig
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


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


Re: servlet-path, path-info and Filters

Posted by Russ Trotter <ru...@yahoo.com>.
Thank for your response Craig.

Just re-read SRV.11 (for the umpteenth time!)

So just so I have understanding, whatever resource (either static file,
servlet, etc) the filter is filtering is irrelavent in determining what is
returned from getServletPath(), getPathInfo() _in the filter_?

>From what you're saying whether it's a filter or a servlet, if the
url-pattern is "/something/*" then that is the return of the
getServletPath() call?  Both being consistent with one-another?

thanks again,
russ


----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Thursday, February 07, 2002 9:09 AM
Subject: Re: servlet-path, path-info and Filters


>
>
>
> The rules are in the Servlet 2.3 Specification, section 11.  In your
> particular example, getServletPath will return "/files" and getPathInfo()
> will return "/foo.jpg".
>
> > Thanks,
> > russ
> >
>
> Craig
>
>



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


Re: servlet-path, path-info and Filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 6 Feb 2002, Russ Trotter wrote:

> Date: Wed, 6 Feb 2002 23:04:40 -0700
> From: Russ Trotter <ru...@yahoo.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: servlet-path, path-info and  Filters
>
> Does anyone here know what the official correct handling of
> ServletRequest.getServletPath() and ServletRequest.getPathInfo() should be?
> More specifically, if I specify a filter with an url-pattern of "/files/*"
> and I make a request to "/context/files/foo.jpg", what should
> getServletPath() and getPathInfo() return?
>
> I've observed some differing behavior between Tomcat 4.0.1 and Jetty in this
> regard and the spec doesn't explicitly clear up the issue between the two.
>

The rules are in the Servlet 2.3 Specification, section 11.  In your
particular example, getServletPath will return "/files" and getPathInfo()
will return "/foo.jpg".

> Thanks,
> russ
>

Craig


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