JSP page指令 关于isErrorPage指定错误页面的使用

来源:互联网 发布:阿里云更换操作系统 编辑:程序博客网 时间:2024/06/06 02:16

isErrorPage 指令用来指定当前JSP页面是不是异常处理页面。
该属性通常与errorPage属性一起使用。

使用方法:在可能出现错误的页面的page属性中,指定errorPage属性,在处理错误的页面指定isErrorPage属性。

举例:

出现错误的页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page errorPage="isErrorPage.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=UTF-8"><title>Insert title here</title></head><body><%int a =10;int b=0;int c=a/b;%></body></html>

处理错误的页面:

<%@ 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=UTF-8"><title>Insert title here</title></head><body>程序发生了错误。</body></html>

isErrorPage属性的值为true或者false,当值为true时说明当前页面就是处理错误的页面。