java JSP - HTTP 状态 404 - 请求的资源不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32285509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSP - HTTP Status 404 - The requested resource is not available
提问by Ori
Hi I am new here and have an issue in JSP. In Eclipse, I created a Dynamic Web Project. I right clicked on WEB-INF folder to create a new folder named jsp. In the folder jsp, I created a new jsp file named "yes.jsp". The jsp file is a simple jsp file.
嗨,我是新来的,在 JSP 中有一个问题。在 Eclipse 中,我创建了一个动态 Web 项目。我右键单击 WEB-INF 文件夹以创建一个名为 jsp 的新文件夹。在文件夹jsp 中,我创建了一个名为“yes.jsp”的新jsp 文件。jsp 文件是一个简单的jsp 文件。
This is yes.jsp
这是 yes.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Yes</title>
</head>
<body>
Yes
</body>
</html>
Now, in my web.xml, when I want to run yes.jsp, I wrote my web.xml as below
现在,在我的 web.xml 中,当我想运行 yes.jsp 时,我将 web.xml 编写如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>WEB-INF/jsp/yes.jsp</welcome-file>
</welcome-file-list>
</web-app>
In the welcome-file I have tried various other alternatives like jsp/yes.jsp, /jsp/yes.jsp, jsp\yes.jsp
在欢迎文件中,我尝试了各种其他替代方案,例如 jsp/yes.jsp、/jsp/yes.jsp、jsp\yes.jsp
But every time I run this, I get the response like
但是每次我运行它时,我都会得到这样的响应
HTTP Status 404 -
HTTP 状态 404 -
type Status report
类型状态报告
message
信息
description The requested resource is not available.
描述 请求的资源不可用。
Apache Tomcat/7.0.55
Apache Tomcat/7.0.55
Please help me to understand where I am going wrong.
请帮助我了解我哪里出错了。
Thank you!
谢谢!
回答by Super Hornet
You should put your jsp files outside of WEB-INF
folder but beside of that.
Folder Structure:
您应该将您的 jsp 文件放在WEB-INF
文件夹之外,但除此之外。文件夹结构:
root/
/WEB-INF
/META-INF
/jsp/yes.jsp
回答by Zishan Mohsin
You can not access WEB-INF folder directly. That's why you are getting this error. You can achieve this by putting name of servlet in welcome file tag. And in that servlet, write the code to dispatch the request object to jsp page present in WEB-INF folder.
您不能直接访问 WEB-INF 文件夹。这就是您收到此错误的原因。您可以通过将 servlet 的名称放在欢迎文件标签中来实现这一点。在那个 servlet 中,编写代码以将请求对象分派到 WEB-INF 文件夹中的 jsp 页面。
Let me know if you have any doubt.
如果您有任何疑问,请告诉我。
Note: Don't forget to do mapping of servlet in web.XML file.
注意:不要忘记在 web.XML 文件中做 servlet 的映射。