tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 8409] New: - HttpServletRequest.getRequestURI() returns wrong URI when forwarded with RequestDispatcher.forward()
Date Tue, 23 Apr 2002 11:09:43 GMT
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:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message