【问题标题】:How to put JSP in WEB-INF correct?如何正确地将 JSP 放入 WEB-INF 中?
【发布时间】:2012-01-29 01:37:37
【问题描述】:

我正在使用 MVC 并希望将我的 JSP 页面放在 WEB-INF 中以避免直接访问它。我在 Web Content 的 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,但无论如何,请帮助我。

【问题讨论】:

    标签: model-view-controller jsp web-inf


    【解决方案1】:

    您似乎通过了路径/jsp/main_read.jsp,而JSP 在/WEB-INF/jsp/jsp/main_read.jsp 中。显然,路径不匹配。将正确的路径传递给getRequestDispatcher()/WEB-INF/jsp/jsp/main_read.jsp

    javadoc 说:

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

    【讨论】:

      猜你喜欢
      • 2011-05-16
      • 2010-12-24
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      相关资源
      最近更新 更多