invalid getRequestURL() after getRequestDispatcher().forward( ... )
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
_From [jelleherold](https://code.google.com/u/101313838082824101834/) on August 14, 2009 12:21:57_
I have a filter like so:
public class F implements Filter {
// ...
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
{
request.getRequestDispatcher("/foo/bar.txt").forward(request, response);
}
}
Then this servlet:
public class S extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
final PrintWriter out = response.getWriter();
out.println("Hello from " + request.getRequestURL());
}
}
If this is configured through web.xml like so:
<filter>
<filter-name>f</filter-name>
<filter-class>guice.test.F</filter-class>
</filter>
<filter-mapping>
<filter-name>f</filter-name>
<url-pattern>/bug</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>s</servlet-name>
<servlet-class>guice.test.S</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
When I request http://localhost:8080/guice.test/bug I get:
Hello from http://localhost:8080/guice.test/foo/bar.txt
If I configure the same thing through guiceFilter, I get
Hello from http://localhost:8080/guice.test/bug
That is incorrect, see http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpServletRequest.html#getRequestURL() In particular:
If this request has been forwarded using
RequestDispatcher.forward(javax.servlet.ServletRequest,
javax.servlet.ServletResponse), the server path in the reconstructed URL
must reflect the path used to obtain the RequestDispatcher, and not the
server path specified by the client.
Can you fix this? Or tell me where to fix it... ?
_Original issue: http://code.google.com/p/google-guice/issues/detail?id=413_
Contributor guide
Assessment
This issue has not been assessed yet.