标签:ring ref cal 处理异常 class nmap code -- property
本文将阐述springmvc中的异常处理。
@Controller
public class ExceptionController{
@ExceptionHandler(value = ArithmeticException.class)
public String test1excp()
{
System.out.println(this);
return "arithmetic";
}
@RequestMapping("/exception1")
@ResponseBody
public String exception1()
{
System.out.println(1/0)
return "exception1";
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
数学异常界面
</body>
</html>
<bean id="simpleMappingExceptionResolver" class=
"org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<map>
<!-- key:异常类别(非全称), 视图名称 -->
<entry key="ArithmeticException" value="arithmetic"/>
</map>
</property>
<!-- 如果在以上配置中找不到异常,则进入此默认异常 -->
<property name="defaultErrorView" value="error"/>
</bean>
error-page是根据返回码处理异常的终极方式。
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
标签:ring ref cal 处理异常 class nmap code -- property
原文地址:https://www.cnblogs.com/alichengxuyuan/p/12554606.html