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

前端 未结 3 871
孤城傲影
孤城傲影 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:09

    The pages under WEB-INF are not accessible from outside the web application.

    Now, since using HttpServletResponse#sendRedirect(), a new request is created by client, so the request is actually sent from the browser, and therefore you cannot have WEB-INF in path to sendRedirect.

    In case of RequestDispatcher, the methods - forward() and include(), doesn't ask the client to create a new request, rather they use the same request to forward to/include a different page from most probably the Servlet Controller. That is why you can give path to a file under WEB-INF, as you are accessing it from inside the web application only.

提交回复
热议问题