Spring MVC 404 Cannot find a page error can be configured directly using Web. XML:
Join in the <web-app/> node:
< Error-page > < Error-code >404</error-code> < location >/web-inf/views/errors/404.jsp</location> </ error-page>
500 run-time error, you can use the Simplemappingexceptionresolver configuration of Spring MVC:
<!--Global Exception Configuration - <BeanID= "Exceptionresolver"class= "Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> < Propertyname= "Exceptionmappings"> <Props> <propKey= "Java.lang.Exception">errors/500</prop> <propKey= "Java.lang.Throwable">errors/500</prop> </Props> </ Property> < Propertyname= "Statuscodes"> <Props> <propKey= "errors/500">500</prop> </Props> </ Property> <!--set the log output level, do not define error log messages such as warnings by default - < Propertyname= "Warnlogcategory"value= "WARN"></ Property> <!--default error page, use this default configuration when you cannot find the corresponding view for the exception specified in mappings above - < Propertyname= "Defaulterrorview"value= "errors/500"></ Property> <!--default HTTP status code - < Propertyname= "Defaultstatuscode"value= "$"></ Property> </Bean>
The view JSP page that corresponds to the 500 error:
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><%@taglib prefix="C"URI="Http://java.sun.com/jsp/jstl/core"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Error</title></Head><Body> <%Exception ex=(Exception) Request.getattribute ("Exception"); %> <H2>Exception:<%=ex.getmessage ()%></H2> <P/> <%Ex.printstacktrace (NewJava.io.PrintWriter (out)); %></Body></HTML>
Test:
Alternatively, you can use inherited handlerexceptionresolver to handle 500 of errors.
Reference article references:
Http://www.cnblogs.com/xguo/p/3163519.html
[Spring MVC]-500/404 error handling