In every common Web site, you will often find a feature that automatically jumps to a page to prompt for error messages when a page fails.
To complete the error page, you must meet two criteria:
1, specify the jump page when the error occurs, specified by the ErrorPage property;
2, error handling page must have a clear identification, through the Iserrorpage property specified.
Here 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, in order to achieve this effect, you must modify the Web.xml file, in which you add the error page operation.
Global error handling can handle two types of errors, one of which is HTTP code errors, such as 404 or 500, and an exception error, such as NullPointerException.
Modify Web.xml file to add error handling, the code is 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>
Case:
In the page input invalid JSP page "http://localhost:8080/JSP/1tiaozhuan_a.jsp", the page will prompt:
The above is a small set to introduce the JSP to create Error page page and automatic jump, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!