相关资料:
《21天学通Java Web开发》
exception对象
1.exception对象用来处理错误异常。
2.如果要使用exception对象,必须指定page中的isErrorPage属性值为“true”。
ExceptionDemo1.jsp
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <%@ page language="java" contentType="text/html;charset=gb2312" isErrorPage="true" %>
2 <%@page import="java.io.PrintStream"%>
3 <html>
4 <head>
5 <title>处理错误异常</title>
6 </head>
7 <body>
8 <%=exception%><br>
9 <%=exception.getMessage()%><br>
10 <%=exception.getLocalizedMessage()%><br>
11 <%
12 exception.printStackTrace(new java.io.PrintWriter(out));
13 %>
14 </body>
15 </html>
ExceptionDemo2.jsp
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <%@ page language="java" contentType="text/html;charset=gb2312" errorPage="ExceptionDemo1.jsp" %>
2 <html>
3 <head>
4 <title>错误页面</title>
5 </head>
6 <body>
7 <%
8 int[] arr = {1,2,3};
9 out.println(arr[3]);
10 %>
11 </body>
12 </html>