`
wj603201
  • 浏览: 62363 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

JSP中使用exception对象显示出错信息

    博客分类:
  • JSP
阅读更多
JSP中使用exception对象显示出错信息

1.是java.lang.Throwable类的一个实例;
2.存储了JSP文件运行时所产生的异常信息;
3.不能在一般的JSP文件中直接使用;
4.只能在错误显示页面中使用,必须在页面的page指令中设定<%@page isErrorPage="true"%>
5.经常被用来捕捉JSP页面中的异常。

实例:当页面出错时,跳转到错误提示页

testerror.jsp:
view plaincopy to clipboardprint?
1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" errorPage="showerror.jsp"%> 
2. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
3. <html> 
4. <head> 
5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
6. <title>TestError</title> 
7. </head> 
8. <body> 
9.     <%=2/0 %> 
10. </body> 
11. </html> 


showerror.jsp:
view plaincopy to clipboardprint?
1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%> 
2. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
3. <html> 
4. <head> 
5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
6. <title>TestError</title> 
7. </head> 
8. <body> 
9. 页面出错!  
10. </body> 
11. </html> 


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics