Java HTTP 状态 - JSP 中未找到 404 资源异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22829269/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:09:35  来源:igfitidea点击:

HTTP status - 404 Resource not found exception in JSP

javajsphttp-status-code-404java-ee-6

提问by Giridharan

I have been stuck up with running hello world program in JSP.When i start my server it showing resource not found exception. please help me to solve this problem. I have mentioned my code below

我一直坚持在 JSP 中运行 hello world 程序。当我启动我的服务器时,它显示资源未找到异常。请帮我解决这个问题。我在下面提到了我的代码

index.jsp:

索引.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>Insert title here</title>
</head>
<body>

</body>
</html>

web.xml

网页.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_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>MySample</display-name>
    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>
</web-app>

采纳答案by Aniket Kulkarni

From comments aboveyou had placed file in wrong folder.

根据上面的评论,您将文件放在错误的文件夹中。

Put your index.jspfile inside WebContentfolder. Do not put in WEB-INFfolder.

将您的index.jsp文件放在WebContent文件夹中。不要放在WEB-INF文件夹中。



WebContent folder

网页内容文件夹

  • The mandatory location of all Web resources, including HTML, JSP, graphic files, and so on.
  • If the files are not placed in this directory (or in a subdirectory structure under this directory), the files will not be available when the application is executed on a server.
  • The Web content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.
  • 所有 Web 资源的强制位置,包括 HTML、JSP、图形文件等
  • 如果文件未放置在此目录中(或此目录下的子目录结构中),则在服务器上执行应用程序时文件将不可用。
  • Web 内容文件夹表示将部署到服务器的 WAR 文件的内容。任何不在 Web 内容文件夹下的文件都被视为开发时资源(例如,.java 文件、.sql 文件和 .mif 文件),并且不会在项目进行单元测试或发布时部署。

Reference

参考

回答by Sanjay Rabari

Your directory structure is important that where you have placed the file and provide that path to welcome-file. hope it helps

您的目录结构很重要,您放置文件的位置并提供欢迎文件的路径。希望能帮助到你

回答by Karthigeyan Vellasamy

Your Welcome index file should start with "/index.jsp" starting with slash if it is directly inside WebContent directory. If it is inside some dirctory like JSP it should be like /JSP/index.jsp

如果您的欢迎索引文件直接位于 WebContent 目录中,那么它应该以“/index.jsp”开头,以斜杠开头。如果它在像 JSP 这样的目录中,它应该像 /JSP/index.jsp