2013-03-20 17 views
0

我在Eclipse中運行簡單Web項目時遇到了一個問題。Eclipse拋出錯誤 - 「文件名引用到」web內容中不存在的「main.html」web.xml的404錯誤

我將首先演示創建我的項目的步驟: -

1)新春模板項目。
2)選擇Spring MVC Project。
3)點擊完成。
4)現在我在「src」下的「webapps」文件夾中創建一個新的文件名「login.html」
5)現在我試圖在web.xml中添加welcome-file標籤。
6)當我這樣做,我從Eclipse的web.xml中得到上述警告。
7)如果我運行應用程序,我得到404錯誤

這是我的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

<!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> 

請幫我解決這個問題,我不明白錯誤是什麼。
在此先感謝。

回答

1

如果你希望你的歡迎文件的工作,然後試着改變你的Servlet映射象下面這樣:

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

目前,所有的請求都將春天的調度servlet和查找請求映射「/ 」。在這種情況下,Controller需要處理「/」的請求,它將返回login.html作爲視圖。您可以查看here以獲取快速入門示例。