为什么使用sendRedirect方法无法访问WEB-INF下的JSP页面? [英] Why the JSP pages under WEB-INF can't be accessible with sendRedirect method?
问题描述
可以使用 RequestDispatcher
的转发方法访问WEB-INF下的那些页面。什么是 sendRedirect
?
Those pages under WEB-INF are accessible using forward method of RequestDispatcher
. Whats wrong with sendRedirect
?
推荐答案
<$ c $下的页面c> WEB-INF 无法从Web应用程序外部访问。
The pages under WEB-INF
are not accessible from outside the web application.
现在,因为使用 HttpServletResponse #sendRedirect()
,客户端创建了一个新请求,因此请求实际上是从浏览器发送的,因此你不能在 sendRedirect
的路径中有 WEB-INF
。
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
.
如果 RequestDispatcher
,方法 - forward()
和 include()
,不要求客户创建新请求,而是使用相同的请求转发/包含很可能是 Servlet控制器的不同页面。这就是为什么你可以在 WEB-INF
下给出一个文件的路径,因为你只是从web应用程序内部访问它。
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.
这篇关于为什么使用sendRedirect方法无法访问WEB-INF下的JSP页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!