2013-08-07 35 views
2

我的web.xml配置如下:404錯誤不是錯誤頁面映射

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 
    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" 
    version="2.5"> 

    <!-- Config here. --> 
<servlet> 
    <servlet-name>SpringConfig</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>SpringConfig</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 

    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath: SpringConfig.xml</param-value> 
    </context-param> 

    <listener>  

    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 

    </listener> 

    <error-page> 
    <exception-type>404</exception-type> 
    <location>/404error.html</location> 
    </error-page> 

</web-app> 

這是位於WebContent文件夾我的簡單404error.html頁:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
The Page You Are Looking For Is Not Available. 
</body> 
</html> 

但我不獲取高於自定義頁面,你們可以告訴我我失蹤了嗎?

回答

1

試試這個。它在我的所有應用程序中工作正常。

<error-page> 
     <error-code>404</error-code> 
     <location>/404error.html</location> 
</error-page> 
+0

謝謝,它的作品。 – commit

0

這似乎是這裏提到你在你的web.xml中的servlet映射提到htm而不是html一個錯字錯誤:

<url-pattern>*.htm</url-pattern> 

試試這個更改爲:

<url-pattern>*.html</url-pattern> 
+0

這不是拼寫錯誤,我在spring配置文件中使用了view resolver來映射.htm url到我的.jsp – commit

0

exception-type更改爲exception-code

<error-page> 
    <exception-code>404</exception-code> 
    <location>/404error.html</location> 
</error-page>