Processing method of page error information of Java EE Web program

Source: Internet
Author: User

When the Web application delivered to the user error, generally do not want to display system-level original error to the user, so it is too unfriendly, will let the user feel inexplicable, in order to make error information more humane principle, the general need for the Web application error handling. Error handling, typically using three pages for processing, 400 errors, 404 errors, and 500 errors, the three errors are most common.

Add in Web.xml:

<error-page>
<error-code>400</error-code>
<location>/error/400.jsp</location>
</error-page>

<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>

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

Then create 400.jsp, 404.jsp, and 500.jsp pages in the Web program separately

For example

404.JSP:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8" iserrorpage= "true"%>
<%
Response.setstatus (HTTPSERVLETRESPONSE.SC_OK);
%>
<title></title>
<body>
404 error, unable to find the page.
</body>

Create 400.jsp and 500.jsp error-handling pages like this

Attention:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8" iserrorpage= "true"%>
<%
Response.setstatus (HTTPSERVLETRESPONSE.SC_OK);
%>

Iserrorpage to be set to True

Response.setstatus (HTTPSERVLETRESPONSE.SC_OK) This must be set, if the use of IE browser enabled "show friendly HTTP error message", but not set this, then your own set error page will not work.

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.