在web.xml中
<?xml version="1.0" encoding="gb2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<error-page>
<error-code>404</error-code>
<location>/pageNotFound.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/internalError.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/NumberFormatException.jsp</location>
</error-page>
</web-app>
测试页面
error500.jsp
<%
int[] a=new int[]{21,1};
out.println(a[10]);
%>
出错的页面
internalError.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<center>
=========发生了内部错误=============
<br>
可能服务器太忙,请稍后再试,如果错误依然存在,请报告管理员,谢谢!
</center>输入:http://127.0.0.1:8080/ch10/error500.jsp之后,效果没有调用internalError.jsp
还有随便输入一个JSP,项目中不存在的也没有调用pageNotFound.jsp