一 Exception对象 二 实例 1、代码1 %@ page language = "java" import = "java.util.*" contentType = "text/html; charset=utf-8" errorPage = "exception.jsp" % % String path = request.getContextPath(); String basePath = request.getScheme
二 实例 1、代码1 <%@ page language = "java" import = "java.util.*" contentType = "text/html; charset=utf-8" errorPage = "exception.jsp" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+ "://" +request.getServerName()+ ":" +request.getServerPort()+path+ "/" ; %> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < html > < head > < base href = " <%= basePath %> " > < title > My JSP 'index.jsp' starting page </ title > < meta http-equiv = "pragma" content = "no-cache" > < meta http-equiv = "cache-control" content = "no-cache" > < meta http-equiv = "expires" content = "0" > < meta http-equiv = "keywords" content = "keyword1,keyword2,keyword3" > < meta http-equiv = "description" content = "This is my page" > <!-- <link rel =" stylesheet " type="text/ css " href ="styles.css"> --> </ head > < body > < h1 > 测试异常的页面 </ h1 > < hr > <% System.out.println(100/0); //抛出运行时异常,算数异常 %> </ body > </ html > 2、代码2 <%@ page language = "java" import = "java.util.*" contentType = "text/html; charset=utf-8" isErrorPage = "true" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+ "://" +request.getServerName()+ ":" +request.getServerPort()+path+ "/" ; %> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < html > < head > < base href = " <%= basePath %> " > < title > My JSP 'index.jsp' starting page </ title > < meta http-equiv = "pragma" content = "no-cache" > < meta http-equiv = "cache-control" content = "no-cache" > < meta http-equiv = "expires" content = "0" > < meta http-equiv = "keywords" content = "keyword1,keyword2,keyword3" > < meta http-equiv = "description" content = "This is my page" > <!-- <link rel =" stylesheet " type="text/ css " href ="styles.css"> --> </ head > < body > < h1 > exception内置对象 </ h1 > < hr > 异常的消息是: <%= exception.getMessage() %> < BR > 异常的字符串描述: <%= exception.toString() %> < br > </ body > </ html > 三 运行结果