JSP creates an error page and jumps automatically. jsp creates an automatic jump

Source: Internet
Author: User

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!

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.