Eclipse引发错误-对"main.html"的“文件名引用" Web内容中不存在的内容" web.xml的404错误 [英] Eclipse throwing error - "file name references to "main.html" that does not exist in web content" 404 error for web.xml

查看:108
本文介绍了Eclipse引发错误-对"main.html"的“文件名引用" Web内容中不存在的内容" web.xml的404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中运行简单的Web项目时,我遇到了一个问题.

I am facing an issue in while running simple web project in Eclipse.

我将首先演示创建项目的步骤:-

I will first demonstrate the steps of creating my project :-

1)新的Spring模板项目.
2)选择Spring MVC项目.
3)单击完成.
4)现在,我在"src"下的"webapps"文件夹中创建一个新文件名"login.html".
5)现在,我尝试在web.xml中添加welcome-file标记.
6)当我这样做时,我从Eclipse的web.xml中得到了上面的警告.
7)如果我运行该应用程序,则会收到404错误

1) New Spring Template Project.
2) Select Spring MVC Project.
3) Click Finish.
4) Now I create a new file name "login.html" in "webapps" folder under "src"
5) Now I tried to add welcome-file tag in the web.xml.
6) When I do that I get the above Warning inside web.xml from Eclipse.
7) If I run the application I get 404 error

这是我的web.xml

This is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>login.html</welcome-file>
</welcome-file-list>

这是我的login.html

This is my login.html

    <!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>
Hello
</body>
</html>

请帮助我,我不明白错误的确切含义.
预先感谢.

Kindly help me out of this I am not understanding what exactly the error is.
Thanks in advance.

推荐答案

如果您希望欢迎文件工作,请尝试如下更改 servlet映射:

If you want your welcome file to work then try changing your servlet-mapping like below:

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/something/</url-pattern>
</servlet-mapping>

当前,所有请求都将发送到Spring的调度程序servlet,并查找"/"的请求映射.在这种情况下,需要一个Controller处理对"/"的请求,该请求将以视图形式返回login.html.您可以在此处查看一个快速入门的例子.

Currently all the requests are going to Spring's dispatcher servlet and looks for a request mapping for "/". In this case a Controller is required to handle the request for "/" that will return login.html as view. You can look here for a quick start example.

这篇关于Eclipse引发错误-对"main.html"的“文件名引用" Web内容中不存在的内容" web.xml的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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