JSP set up error page page and automatically jump _jsp programming

Source: Internet
Author: User
Tags error handling

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.