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);
%>
<html>
<head>
<title></title>
</head>
<body>
404 error, unable to find the page.
</body>
</html>

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

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.