JSP creates an error page and jumps automatically. jsp creates an automatic jump
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">
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:
The above section describes how to create a JSP error page and automatically jump to the page. I hope it will be helpful to you. If you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!