Jsp automatically jumps when an error page is created, and jsp automatically jumps
In common web sites, a function is often found: When a page error occurs, an error message is automatically displayed on a page.
To complete the operation on the error page, you must meet two conditions:
1. Specify the page to jump when an error occurs, which is specified through the errorPage attribute;
2. The error handling page must be clearly identified and specified through the isErrorPage attribute.
The following is the error page: errorPage. jsp
The Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<% @ Page isErrorPage = "true" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> My JSP 'errorpage. jsp 'starting page </title>
</Head>
<Body>
<H1> A program error occurs. Contact the administrator! </H1>
</Body>
</Html>
Of course, you can also specify global error handling in the entire virtual directory. To achieve this effect, you must modify the web. xml file and add an error page to it.
Global error handling can handle two types of errors: HTTP code errors, such as 404 or 500, and NullPointerException.
Modify the web. xml file and add error handling code as follows:
<Error-page>
<Error-code> 500 </error-code>
<Location>/error/errorPage. jsp </location>
</Error-page>
<Error-page>
<Error-code> 404 </error-code>
<Location>/error/errorPage. jsp </location>
</Error-page>
<Error-page>
<Exception-type> java. lang. NullPointerException </exception-type>
<Location>/error/errorPage. jsp </location>
</Error-page>
Example:
Enter "http: // localhost: 8080/jsp/1tiaozhuan_a.jsp" in the invalid JSP page. The following message is displayed: