您的位置:首页 > 移动开发

Springmvc SimpleMappingExceptionResolver

2016-02-24 00:00 253 查看
摘要: SimpleMappingExceptionResolver 异常处理

@RequestMapping(value="/testSimpleMappingExceptionResolver")
public String testSimpleMappingExceptionResolver(@RequestParam("i") Integer i){
int[] j = new int[i];
System.out.println("testSimpleMappingExceptionResolver....");
System.out.println(j[20]);
return "success";
}

springmvc.xml

<!-- 配置使用SimpleMappingExceptionResolver 来映射异常 -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.ArrayIndexOutOfBoundsException">error</prop>
</props>
</property>
<!-- exceptionAttribute 默认value为exception 也可以改    会自动注入请求域 -->
<property name="exceptionAttribute" value="exception"></property>
</bean>


error.jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<h4>error</h4>
${exception }
</body>
</html>


访问 http://localhost:8080/springmvc_1/testSimpleMappingExceptionResolver?i=10

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息