404, 500, 503 wrong configuration, improve user experience

Source: Internet
Author: User
Tags exception handling throwable log4j

In recent work, the community provides a unified presentation page for three exceptions (404/500/503) to improve user perceptions, while defining a standard log output format for 404/500 of two errors.

404 and 500 Wrong configuration

Please remove the configuration from the program that originally handled the exception page through spring Exceptionresolver, and refer to the following instructions for the applicability of Exceptionresolver. Applies to all business-related exception situations, which means that you can handle all exceptions that are explicitly thrown in your application through Exceptionresolver. For example, when a variety of bank account operations, the program may be in different locations to throw out the balance of the exception, when the page can be forwarded by Exceptionresolver to the unified account balance of insufficient error display page for all due to the unforeseen reasons for the program caused by the exception, The following exception handling page should be used to handle web.xml configuration

Add the following code fragment:

<error-page>
    <error-code>404</error-code>
    <location>/Point/Abnormal Display page address </location >
</error-page>
<error-page>
    <error-code>500</error-code>
    < location>/Point/Exception Display page address </location>
</error-page>
Abnormal Display page

Refer to Error_all.jsp

<% @page contenttype= "text/vnd.wap.wml;charset=utf-8"%><?xml version= "1.0" encoding= "UTF-8"? ><%
int statusCode = (Integer) request.getattribute ("Javax.servlet.error.status_code");
String message = (string) request.getattribute ("Javax.servlet.error.message");
String servletname = (string) request.getattribute ("Javax.servlet.error.servlet_name");
String uri = (string) request.getattribute ("Javax.servlet.error.request_uri");
Throwable t = (throwable) request.getattribute ("Javax.servlet.error.exception");
Class exception = (Class) Request.getattribute ("Javax.servlet.error.exception_type");
if (StatusCode = =) {
    logger.error (statusCode + "|" + Message + "|" + Servletname + "|" + URI) + "|" + Exception.getname (), T); 
}
Else if (StatusCode = = 404) {
    logger.error ( StatusCode + "|" + Message + "|" + Servletname + "|" + URI); 
}

String querystring = request.getquerystring ();
String url = uri + (querystring = null | | querystring.length () = 0? "": "?" + querystring);
URL = url.replaceall ("&amp;", "&"). ReplaceAll ("&", "&amp;");

%><! DOCTYPE WML public "-//wapforum//dtd WML 1.1//en" "HTTP://WWW.WAPFORUM.ORG/DTD/WML_1_1.DTD" >
<wml>
<card title= "page <%=statusCode%> error" >
<p><%
if (StatusCode = = 404) {
%> Sorry, you have not found the address of the page you visited, please contact the administrator to resolve this issue .<br/><br/>
<a href= "<%=url%>" > Refresh to see if you can access the </a><br/><%
}
else {
%> Sorry, the page you visited has a little internal problem, please <a href= "<%=url%>" > Refresh </a> re-access, or go to another page, and then come again ~<br/><br/ ><%
}
%><anchor> return to the page just now <prev/></anchor><br/>
<a href= "Http://i.kong.net/<%=request.getAttribute (" UID ")!= null? "Uid=" + request.getattribute ("UID"): "%>" > Return to the Air home </a><br/>
<br/>
</p>
</card>
</wml>
<%!
private static final Org.apache.commons.logging.Log LOGGER = Org.apache.commons.logging.LogFactory.getLog ("Page_ Errors ");
%>

Output format for error messages

Similar to:

Error 08/10/27 15:22:58 page_errors-404|resin-jsp|/f/s.jsp
error 08/10/27 15:25:03 page_errors-500|null|/f/i/ G.jsp|java.lang.runtimeexception
First Item: Error code (JAVAX.SERVLET.ERROR.STATUS_CODE) Second item: servlet name (javax.servlet.error.servlet_name) Third: Requested URI ( Javax.servlet.error.request_uri) Fourth: Exception class name (Javax.servlet.error.exception_type), only occurs at 500 Configuration of log4j
<appender name= "page_error_rolling" class= "Org.apache.log4j.DailyRollingFileAppender" >
    <param name= " File "value=" actual log path "/> <param name= Encoding" value= "GBK"/> <param name=
    "Immediateflush" value = "true"/>
    <layout class= "Org.apache.log4j.PatternLayout" >
        <param name= "Conversionpattern" Value= "%p%d{yy/mm/dd HH:mm:ss}-%m%n"/>
    </layout>
</appender>
<logger name= "Page_ Errors ">
    <level value=" ERROR "/>
    <appender-ref ref=" page_error_rolling "/>
</logger >
503 Wrong configuration configuration of http.conf in Apache
ErrorDocument 503 http://i.kong.net/503.jsp

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.