如何将JSP正确放入WEB-INF中?
我正在使用 MVC,并且希望将 JSP 页面放在 WEB-INF 中以避免直接访问它。我在 Web 内容的 jsp 文件夹中有一个 index.jsp 页面和其他页面,并且它可以工作。它看起来像这样:
-Web Content
-index.jsp
-jsp
--main_read.jsp
--...
顺便说一句,index.jsp 是我的登录页面,无论用户是否登录,在我使用的控制器中
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("jsp/main_read.jsp");
dispatcher.forward(request, response);
我工作得很好,但是当我尝试将 JSP 放入 WEB-INF 时,它失败了:
-Web Content
-index.jsp
-WEB-INF
--jsp
---jsp
----main_read.jsp
----...
并给出了像这样的错误
HTTP Status 404 - /Libruary/jsp/main_read.jsp
type Status report
message /Libruary/jsp/main_read.jsp
description The requested resource (/Libruary/jsp/main_read.jsp) is not available.
Apache Tomcat/6.0.26
可能问题出在页面路径中,我在 dispatcher.forward
中编写,但无论如何,请帮助我。
I'm using MVC and want to put my JSP pages in WEB-INF to avoid direct access to it. I have an index.jsp page and other pages in jsp folder in Web Content and it works. It looks like this:
-Web Content
-index.jsp
-jsp
--main_read.jsp
--...
By the way, index.jsp is my login page and whether user is logged, in controller I use
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("jsp/main_read.jsp");
dispatcher.forward(request, response);
I works perfect, but when I'm trying to put my JSP in WEB-INF it fails:
-Web Content
-index.jsp
-WEB-INF
--jsp
---jsp
----main_read.jsp
----...
And gives an error like this
HTTP Status 404 - /Libruary/jsp/main_read.jsp
type Status report
message /Libruary/jsp/main_read.jsp
description The requested resource (/Libruary/jsp/main_read.jsp) is not available.
Apache Tomcat/6.0.26
Probably the problem is in the page path, I write in dispatcher.forward
, but anyway, help me please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎传递了路径
/jsp/main_read.jsp
,并且JSP位于/WEB-INF/jsp/jsp/main_read.jsp
中。显然,路径不匹配。将正确的路径传递给getRequestDispatcher()
:/WEB-INF/jsp/jsp/main_read.jsp
。javadoc 说:
You seem to pass the path
/jsp/main_read.jsp
, and the JSP is in/WEB-INF/jsp/jsp/main_read.jsp
. Obviously, the paths don't match. Pass the correct path togetRequestDispatcher()
:/WEB-INF/jsp/jsp/main_read.jsp
.The javadoc says: