DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8409>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8409
HttpServletRequest.getRequestURI() returns wrong URI when forwarded with RequestDispatcher.forward()
Summary: HttpServletRequest.getRequestURI() returns wrong URI
when forwarded with RequestDispatcher.forward()
Product: Tomcat 4
Version: 4.0.3 Final
Platform: PC
OS/Version: Windows 9x
Status: NEW
Severity: Normal
Priority: Other
Component: Catalina
AssignedTo: tomcat-dev@jakarta.apache.org
ReportedBy: thomas@botany.ch
When forwarding a HttpServletRequest with
RequestDispatcher.forward(HttpServletRequest req, HttpServletResponse res),
calling - in the servlet the request is forwarded to - the method
HttpServletRequest.getRequestURL() returns the request URL of the CALLING
servlet whereas the method HttpServletRequest.getRequestURI() returns the
request URI of the CALLED servlet.
Example:
Test servlet 1: The servlet ExceptionSource throws an exception and forwards to
the servlet ExceptionHandler.
public class ExceptionSource extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
String s = null;
s.charAt(0);
} catch (NullPointerException e) {
RequestDispatcher dispatcher =
request.getRequestDispatcher("/servlet/ExceptionHandler");
dispatcher.forward(request, response);
}
}
}
Test servlet 2: The servlet ExceptionHandler calls
HttpServletRequest.getRequestURL() and HttpServletRequest.getRequestURI().
public class ExceptionHandler extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("request URL: " + request.getRequestURL());
out.println("request URI: " + request.getRequestURI());
}
}
The output of ExceptionHandler is:
request URL: http://localhost/servlet/ExceptionSource
request URL: /servlet/ExceptionHandler
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>