/WEB-INF中的JSP返回“HTTP状态404请求的资源不可用"; [英] JSP in /WEB-INF returns "HTTP Status 404 The requested resource is not available"

查看:63
本文介绍了/WEB-INF中的JSP返回“HTTP状态404请求的资源不可用";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 JSP 文件.

I created a JSP file.

sample.jsp

<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <title>Insert title here</title>
  </head>
  <body>
    This is jsp program
  </body>
</html>

我把它放在 samplejsp 项目中.

I placed it here in the samplejsp project.

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

我在以下网址打开了它.

I opened it on the following URL.

http://localhost:8080/samplejsp/sample.jsp

但在浏览器中显示以下错误.

But it shows the following error in browser.

请求的资源 (/sample.jsp) 不可用.

404 ERROR

The requested resource (/sample.jsp) is not available.

推荐答案

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.

这篇关于/WEB-INF中的JSP返回“HTTP状态404请求的资源不可用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆