Springmvc SimpleMappingExceptionResolver
2016-02-24 00:00
253 查看
摘要: SimpleMappingExceptionResolver 异常处理
springmvc.xml
error.jsp页面
访问 http://localhost:8080/springmvc_1/testSimpleMappingExceptionResolver?i=10
@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
相关文章推荐
- Spring MVC--拦截器实现和用户登陆例子
- Java简单实现SpringMVC+MyBatis分页插件
- SpringMVC文件上传 多文件上传实例
- SpringMVC restful 注解之@RequestBody进行json与object转换
- spring mvc4的日期/数字格式化、枚举转换示例
- 解决springmvc+mybatis+mysql中文乱码问题
- SpringMVC上传图片与访问
- SpringMVC入门小程序 -- Myeclipse 9.1下
- SpringMVC+Spring3+Hibernate4
- SpringMVC+MyBatis项目总结(一)
- SpringMVC+MyBatis项目总结(三)
- SpringMVC+MyBatis项目总结(四)
- springMVC+spring+Mybatis
- SpringMVC+mybatis+Spring框架整合+简单实现的demo
- Springmvc与jasperreport结合生成报表的一种方法 4000
- 搭建分布式架构2--CentOs下安装Tomcat7(环境准备)
- 搭建分布式架构4--ZooKeeper注册中心安装
- 搭建分布式架构5--ZooKeeper 集群的安装 3ff0
- 蓝缘系统第三版本即将开源;基于springMVC+Apache shiro 1.2.3+Mybai
- SpringMVC 集成 JFinal Dao