且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

/WEB-INF中的JSP返回“HTTP状态404请求的资源不可用";

更新时间:2021-12-28 23:46:32

404 只是意味着 未找到".

404 simply means "Not Found".

URL 错误(注意:区分大小写!),或者资源不在您认为的位置.

Either the URL is wrong (note: case sensitive!), or the resource is not there where you think it is.

只需验证 URL 和/或验证资源是否在您期望的位置.您将 sample.jsp 放在 /WEB-INF 文件夹中.这样,如果不通过前端控制器 servlet 调用,就不能公开访问它.

Just verify the URL and/or verify if the resource is there where you'd expect it to be. You placed sample.jsp in /WEB-INF folder. This way it is not publicly accessible without calling through a front controller servlet.

把它放在/WEB-INF之外.

samplejsp
 `-- WebContent
      |-- WEB-INF
      `-- sample.jsp

如果你想把它保存在 /WEB-INF 中,那么你需要创建一个前端控制器 servlet,它在 doGet() 方法中转发给它,如下所示.

If you want to keep it in /WEB-INF, then you need to create a front controller servlet which forwards to it in doGet() method as below.

request.getRequestDispatcher("/WEB-INF/sample.jsp").forward(request, response);

终于打开"了只需调用 servlet 的实际 URL 而不是 JSP 的虚构 URL.

Finally "open" the JSP by just calling servlet's actual URL instead of JSP's fictive URL.