问题
I am facing an issue in while running simple web project in Eclipse.
I will first demonstrate the steps of creating my project :-
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
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>
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.
回答1:
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>
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.
来源:https://stackoverflow.com/questions/15516213/eclipse-throwing-error-file-name-references-to-main-html-that-does-not-exis