试用page指令中的errorPage属性和isErrorPage属性,编写程序实现
一个简单的错误处理机制;
Error.jsp的代码为:
<%@ page language="java" contentType="text/html; charset=gbk"
errorPage="error2.jsp" isErrorPage="false" language="java"%>
<!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=gbk">
<title>Insert title here</title>
</head>
<body>
<%
int c=9/0;
%>
</body>
</html>
error2.jsp中的代码中,iserrorpage必须设为“true,”否则不能用exception!
Error2.jsp的代码为:
<%@ page language="java" contentType="text/html; charset=gbk"
isErrorPage="true" errorPage="" language="java"%>
<!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=gbk">
<title>Insert title here</title>
</head>
<body>
<h1>
出现错误,错误信息为:
</h1>
<%=exception.getMessage() %>
</body>
</html>