Why the JSP pages under WEB-INF can't be accessible with sendRedirect method?

前端 未结 3 875
孤城傲影
孤城傲影 2020-12-20 07:46

Those pages under WEB-INF are accessible using forward method of RequestDispatcher. Whats wrong with sendRedirect?

3条回答
  •  不思量自难忘°
    2020-12-20 08:10

    RequestDispatcher forward method pass the control of the request to another servlet or jsp without telling anything about the request dispatch to the client browser. Therefore request dispatch happens completely in the server side, hence you can specify the path

    sendRedirect method stop further processing of the request and send http status code "301" and URL of the location to be redirected to the client browser in the response header. Server does not have control of this request after sending the redirect related HTTP header to the client browser. Client browser sees http status 301 and then it know it should send a new request to the url in "Location" http header which is set by server. and Client browser sends a new request to the new URL and it will be processed by the server as another normal request.Thus sendRedirect is handled through the client browser, so specifying the path does not work.

提交回复
热议问题