Bug 33640 - RequestDispatcher.forward forwards to incorrect resource when the request is wrapped with a set servletPath
Summary: RequestDispatcher.forward forwards to incorrect resource when the request is ...
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.5.7
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2005-02-18 18:05 UTC by Mike Traum
Modified: 2005-02-18 09:53 UTC (History)
0 users

Simple war file displaying the problem (6.63 KB, application/octet-stream)
2005-02-18 18:06 UTC, Mike Traum

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Traum 2005-02-18 18:05:21 UTC
If a HttpServletRequestWrapper overrides the getServletPath() method to return
it's own value, a RequestDispatcher.forward will forward to that resource, even
when obtaining the RequestDispatcher with getRequestDispatcher(String). I
believe the servlet spec says that it should forward to the resource specified
in getRequestDispatcher.

This also occurs on the latest Tomcat 4 - should I open a bug there too?
Comment 1 Mike Traum 2005-02-18 18:06:42 UTC
Created attachment 14316 [details]
Simple war file displaying the problem
Comment 2 Remy Maucherat 2005-02-18 18:09:09 UTC
Please explain the problem better.
Comment 3 Mike Traum 2005-02-18 18:12:49 UTC
I'm not sure how to describe it better. Will the attached .war file (a very
simple application made to display this problem) not suffice?
Comment 4 Remy Maucherat 2005-02-18 18:21:13 UTC
Cool, but I think it happens because the request, which is mapped to the Jasper
servlet (*.jsp) will look at the servlet path to decide which JSP to serve.
Since your wrapper will still be at the top of the wrapper "stack" after the
forward as per the spec (this is so that wrapping is actually useful), the path
specified in the wrapper will be used.
Comment 5 Remy Maucherat 2005-02-18 18:21:40 UTC
The case is much simpler than what I though, so it is enough.
Comment 6 Mike Traum 2005-02-18 18:38:38 UTC
But SRV.14.2.8 states:
"Returns a RequestDispatcher object that acts as a wrapper for the resource
located at the given path. A RequestDispatcher object can be used to forward a
request to the resource or to include the resource in a response. The resource
can be dynamic or static."

Doesn't that state the it should forward to the String specified in

Also, SRV.14.2.5 states:
RequestDispatcher.forward(ServletRequest, ServletResponse)
"For a RequestDispatcher obtained via getRequestDispatcher(), the ServletRequest
object has its path elements and parameters adjusted to match the path of the
target resource."

Are you saying there's a conflict elsewhere in the spec?
Comment 7 Remy Maucherat 2005-02-18 18:53:21 UTC
I suggest you read my answer.

Here it is another way:
- /uri.jsp maps to Jasper *.jsp
- Request is fowarded to the JSP servlet
- Your wrapper is the top of the wrapper stack (will be called first by Jasper)
- The main Jasper servlet uses getServletPath to determine which JSP it should send

Workaround: precompile (this maps your individual JSPs as servlets, and avoids

Please do not reopen the report, or I'll close the report again without any
further comments.