Home  >  Article  >  Java  >  what is jsp exeption

what is jsp exeption

(*-*)浩
(*-*)浩Original
2019-06-01 10:19:172326browse

Exception is one of the nine built-in objects of jsp. The exception object is an exception object. When an exception occurs during the running of the page, this object is generated. If the JSP page applies this object, isErrorPage must be set to true, otherwise it cannot be compiled

what is jsp exeption

Usual usage

1 .exception.getMessage() Returns a message describing the exception

2.exception.toString() Returns a brief description message about the exception

3.exception.printStackTrace() Displays the exception and its stack trace

4.exception.fillInStackTrace() rewrites the execution stack trace of the exception

Example

(1) Create an exception_test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"  errorPage="exception.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body> 
    <%
    out.println(100/0);
     %>
  </body>
</html>

Required: errorPage="exception.jsp" means that when there is an exception, it will be handed over to exception.jsp for processing
(2) Create exception.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isErrorPage="true"%>
<html>
  <body>
    异常消息是:<%=exception.getMessage() %><br>
  异常描述信息:<%=exception.toString() %>   
  </body>
</html>

Note: exception objects are only valid in exception handling pages.

Note: Since only JSP scripts and output expressions will generate the code in the _jspx_page_context method, there is no need to handle exceptions in these two parts of the code. However, the declaration part of JSP is still forced to handle checked exceptions, and the JSP exception handling mechanism does not work on JSP declarations.

In the JSP exception handling mechanism, one exception handling page can handle exceptions in the script parts of multiple JSP pages. The exception handling page is determined by the errorPage attribute of the Page directive.

The above is the detailed content of what is jsp exeption. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn