Customize Java Web application error pages

Source: Internet
Author: User

Original translated from: http://www.diybl.com/course/3_program/java/javajs/20071111/85327.html

Step 1: Create a JSP page that displays error information. The content is as follows:

<% @ page Language = "Java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "iserrorpage =" true "%>
<% @ taglib uri =" http://java.sun.com/jsp/jstl/core "prefix =" C "%>




system execution error


system execution an error occurred, the information is described as follows:

error status Code : $ {pagecontext. errordata. statuscode }

error page: $ {pagecontext. errordata. requesturi}

error message: $ {pagecontext. exception}


error stack information:


$ {trace}





Of course, this is only used to Display Error-related information, which contains the vast majority of Error-related information. You can use this information to customize your error display.

Step 2: configure the Web. xml file and add an error page.
<Error-page>
<Exception-type> JAVA. Lang. Exception </exception-type>
<Location>/error. jsp </location>
</Error-page>

This configuration indicates that if an exception of the Java. Lang. Exception type (including subclass) occurs on the JSP page or servlet, it will be forwarded to the error. jsp page for processing.

<Error-page>
<Error-code> 500 </error-code>
<Location>/error. jsp </location>
</Error-page>

This configuration is also possible, indicating that when a 500 error occurs, it is transferred to the error. jsp page for processing.

Is it easy? You can configure multiple <error-page> sections to forward different types of errors to different error handling pages. The methods are available, configure your personalized error message display.

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.