/WEB-INF中的JSP返回"HTTP状态404请求的资源不可用". [英] JSP in /WEB-INF returns "HTTP Status 404 The requested resource is not available"
问题描述
我创建了一个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
项目中.
samplejsp
`-- WebContent
`-- WEB-INF
`-- sample.jsp
我在以下URL上打开了它.
I opened it on the following URL.
http://localhost:8080/samplejsp/sample.jsp
但是它在浏览器中显示以下错误.
But it shows the following error in browser.
404错误
请求的资源(/sample.jsp)不可用.
404 ERROR
The requested resource (/sample.jsp) is not available.
推荐答案
404只是意味着未找到" .
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,该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.
- What is WEB-INF used for in a Java EE web application?
- Calling servlet from JSP
- doGet and doPost in Servlets
这篇关于/WEB-INF中的JSP返回"HTTP状态404请求的资源不可用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!