2013-08-07 33 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>