我已将web.xml配置如下:
<?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>
但是我没有超越自定义页面,你能告诉我我错过了什么吗?
答案 0 :(得分:1)
试试这个。它在我的所有应用程序中运行良好。
<error-page>
<error-code>404</error-code>
<location>/404error.html</location>
</error-page>
答案 1 :(得分:0)
这似乎是一个拼写错误,你在web.xml中提到了htm
而不是html
的servlet-mapping,如下所述:
<url-pattern>*.htm</url-pattern>
尝试将其更改为:
<url-pattern>*.html</url-pattern>
答案 2 :(得分:0)
将exception-type
更改为exception-code
<error-page>
<exception-code>404</exception-code>
<location>/404error.html</location>
</error-page>