exception对象:
exception对象时一个异常对象,当一个页面在运行过程中发生了异常,就产生这个对象,如果一个jsp页面要应用此对象,就必须在page指令里把isErrorPage设置为true,否则无法编译,它实际上是java.lang.Throwable的对象。
常用方法:
- String getMessage() 返回描述异常的消息。
- String toString() 返回关于异常的简短描述消息
exception.jsp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" errorPage="error_exception.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>exception内置对象
</title>
</head>
<body>
<%
System.out.println(10/0); //算数异常
%>
</body>
</html>
|
error_exception.jsp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" isErrorPage="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>exception内置对象-异常处理页面
</title>
</head><title>exception内置对象-异常处理页面
</title>
<body>
异常消息:
<%=exception.getMessage() %>
异常描述:
<%=exception.toString() %>
</body>
</html>
|
作者地址:http://www.bcoder.cn/?p=899