如何将JSP放入WEB-INF中?

And*_*And 3 model-view-controller jsp web-inf

我正在使用MVC并希望将我的JSP页面放在WEB-INF中以避免直接访问它.我有一个index.jsp页面和Web内容的jsp文件夹中的其他页面,它的工作原理.它看起来像这样:

-Web Content
-index.jsp
-jsp
--main_read.jsp
--...
Run Code Online (Sandbox Code Playgroud)

顺便说一句,index.jsp是我的登录页面,用户是否已登录,在我使用的控制器中

RequestDispatcher dispatcher =
        getServletContext().getRequestDispatcher("jsp/main_read.jsp");
dispatcher.forward(request, response);
Run Code Online (Sandbox Code Playgroud)

我工作得很完美,但是当我试图将我的JSP放入WEB-INF时它会失败:

-Web Content
-index.jsp
-WEB-INF
--jsp
---jsp
----main_read.jsp
----...
Run Code Online (Sandbox Code Playgroud)

并给出这样的错误

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
Run Code Online (Sandbox Code Playgroud)

可能问题是在页面路径中,我写了dispatcher.forward,但无论如何,请帮助我.

JB *_*zet 8

你似乎传递了路径/jsp/main_read.jsp,JSP就在/WEB-INF/jsp/jsp/main_read.jsp.显然,路径不匹配.将正确的路径传递给getRequestDispatcher():/WEB-INF/jsp/jsp/main_read.jsp.

javadoc中说:

路径名必须以/开头,并且被解释为相对于当前上下文根

  • 谢谢你,对不起愚蠢的问题=) (2认同)