Springmvc exception handling, Simplemappingexceptionresolver can only handle exceptions easily
When an exception occurs, the exception information is displayed by jumping to the specified page according to the type of exception that occurred
Exceptioncontroller.java processor
PackageCom.orange.controller;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.servlet.ModelAndView;Importcom.orange.exception.NameException;Importcom.orange.exception.PasswordException, @Controller @requestmapping ("/exception") Public classExceptioncontroller {@RequestMapping ("/simple") PublicString doexception () {inti = 3/0; return"/showexception.jsp"; } }
defaultexception.jsp the page where the exception jump occurred
<%@ Page Language="Java"ContentType="text/html; CHARSET=GBK"pageencoding="GBK"%><%@ taglib Prefix="C"URI="Http://java.sun.com/jstl/core" %><%@ taglib Prefix="fn"URI="http://java.sun.com/jsp/jstl/functions" %> <% StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!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=GBK"><Basehref= "<%=basepath%>"><title>Defaultexceptionpage</title></Head><Body>error! Defaultexceptionpage<BR>message:<C:outvalue= "${ex.message}"></C:out></Body></HTML>
SPRINGMVC Configuration Simplemappingexceptionresolver
<Beanclass= "Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <!--specifies all exceptions that are not specified and jumps to the page - < Propertyname= "Defaulterrorview"value= "/defaultexception.jsp" /> <!--carry exception object when jumping - < Propertyname= "Exceptionattribute"value= "Ex"></ Property> </Bean>
SPRINGMVC Study Note four: Simplemappingexceptionresolver exception handling