JAVA-JSP内置对象之exception对象用来处理错误异常

 

相关资料:
《21天学通Java Web开发》

exception对象
1.exception对象用来处理错误异常。
2.如果要使用exception对象,必须指定page中的isErrorPage属性值为“true”。

ExceptionDemo1.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" isErrorPage="true" %>
 2 <%@page import="java.io.PrintStream"%>
 3 <html>
 4 <head>
 5   <title>处理错误异常</title>
 6 </head>
 7 <body>
 8   <%=exception%><br>
 9   <%=exception.getMessage()%><br>
10   <%=exception.getLocalizedMessage()%><br>
11   <%
12     exception.printStackTrace(new java.io.PrintWriter(out));
13   %>
14 </body>
15 </html>
View Code

 

ExceptionDemo2.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" errorPage="ExceptionDemo1.jsp" %>
 2 <html>
 3 <head>
 4   <title>错误页面</title>
 5 </head>
 6 <body>
 7   <%
 8     int[] arr = {1,2,3};
 9     out.println(arr[3]);
10   %>
11 </body>
12 </html>
View Code

 

相关文章:

  • 2021-07-22
  • 2021-07-09
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-02-09
  • 2021-05-23
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案