在一次项目中在配置自定义404和500页面的时候不成功,刚开始在web.xml配置
8<error-page>
9 <error-code>404</error-code>
10 <location>/building.jsp</location>
11</error-page>
12
13<error-page>
14 <error-code>500</error-code>
15 <location>/error.jsp</location>
16</error-page>
以为这样就可转到自己定义的错误页面了。但是不行,这样配置了以后只是跳到了浏览器(IE8)的本身404和500页面。
我们需要在自己定义的错误页面加上两句话。
1、在page标签元素加上 isErrorPage="true"
2、再加上这么一段代码
<%
response.setStatus(HttpServletResponse.SC_OK);
%>
所以我页面的头部就变成了如下
<%@ page language="java" contentType="text/html; charset=UTF-8" isErrorPage="true"
pageEncoding="UTF-8"%>
<%
response.setStatus(HttpServletResponse.SC_OK);
%>
这样就可以成功捕获错误代码后,跳转到相应路径的错误页面了。
文采不好!希望各位能看得明白。借此希望能帮到碰到这个问题还没解决的。