SpringMVC学习笔记四:SimpleMappingExceptionResolver异常处理
SpringMVC的异常处理,SimpleMappingExceptionResolver只能简单的处理异常
当发生异常的时候,根据发生的异常类型跳转到指定的页面来显示异常信息
ExceptionController.java 处理器
package com.orange.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import com.orange.exception.NameException;
import com.orange.exception.PasswordException; @Controller
@RequestMapping("/exception")
public class ExceptionController { @RequestMapping("/simple")
public String doException(){ int i = 3 / 0; return "/showException.jsp";
} }
defaultException.jsp 发生异常跳转的页面
<%@ 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" %>
<%
String path = request.getContextPath();
String basePath = 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>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<base href="<%=basePath %>">
<title>DefaultExceptionPage</title>
</head>
<body>
ERROR! DefaultExceptionPage<br>
message: <c:out value="${ex.message }"></c:out>
</body>
</html>
springMVC配置SimpleMappingExceptionResolver
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!-- 指定所有没有指定的异常,都跳转到该页面 -->
<property name="defaultErrorView" value="/defaultException.jsp" />
<!-- 跳转时携带异常对象 -->
<property name="exceptionAttribute" value="ex"></property>
</bean>
SpringMVC学习笔记四:SimpleMappingExceptionResolver异常处理的更多相关文章
- SpringMVC学习笔记(四)
一.Controller接受网页参数. 1.使用方法的形参来接受 //使用基本类型和字符串来接受 @RequestMapping(value="/param2.do") publi ...
- SpringMVC 学习笔记(四) 处理模型数据
Spring MVC 提供了下面几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体就可以通过该对象加入模型数据 – Map及Model: ...
- SpringMVC学习笔记五:HandlerExceptionResolver异常处理
继承HandlerExceptionResolver自定义异常处理器 控制器ExceptionController.java package com.orange.controller; import ...
- SpringMVC 学习笔记(四)
41. 尚硅谷_佟刚_SpringMVC_返回JSON.avi SpringMVC中使用@ResponseBody注解标注业务方法,将业务方法的返回值做成json输出给页面 导包: 除了一些sprin ...
- SpringMVC学习笔记四:数据绑定
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6831344.html 参考:http://www.cnblogs.com/HD/p/4107674.html ...
- springmvc学习笔记--REST API的异常处理
前言: 最近使用springmvc写了不少rest api, 觉得真是一个好框架. 之前描述的几篇关于rest api的文章, 其实还是不够完善. 比如当遇到参数缺失, 类型不匹配的情况时, 直接抛出 ...
- 史上最全的SpringMVC学习笔记
SpringMVC学习笔记---- 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于Spring ...
- SpringMVC学习笔记之二(SpringMVC高级参数绑定)
一.高级参数绑定 1.1 绑定数组 需求:在商品列表页面选中多个商品,然后删除. 需求分析:功能要求商品列表页面中的每个商品前有一个checkbok,选中多个商品后点击删除按钮把商品id传递给Cont ...
- springmvc学习笔记(简介及使用)
springmvc学习笔记(简介及使用) 工作之余, 回顾了一下springmvc的相关内容, 这次也为后面复习什么的做个标记, 也希望能与大家交流学习, 通过回帖留言等方式表达自己的观点或学习心得. ...
随机推荐
- ubuntu 编译VLC3.0.0
参考链接 https://blog.csdn.net/u014755412/article/details/78874038 https://www.cnblogs.com/wpjamer/p/919 ...
- arg min,arg max, e.g ,i.e
数学中常见的arg min,arg max 是什么意思 arg 是变元(即自变量argument)的英文缩写 arg min 就是使后面这个式子到达最小值时的变量的取值 arg max 就是使后面这个 ...
- vi——终端中的编辑器
vi--终端中的编辑器 目标 vi 简介 打开和新建文件 三种工作模式 常用命令 分屏命令 常用命令速查图 01. vi 简介 1.1 学习 vi 的目的 在工作中,要对 服务器 上的文件进行 简单 ...
- 2019牛客暑期多校训练营(第五场)B.generator 1
传送门:https://ac.nowcoder.com/acm/contest/885/B 题意:给出,由公式 求出 思路:没学过矩阵快速幂.题解说是矩阵快速幂,之后就学了一遍.(可以先去学一下矩阵快 ...
- SQL: all 运算符 可以 表示 非空(NOT NULL)的意思吗?
select count(all grade) from customer; SELECT COUNT(DISTINCT customer_id) FROM customer WHERE grade ...
- Python笔记_第四篇_高阶编程_GUI编程之Tkinter_1.使用Python进行GUI编程的概述
1. GUI概述: GUI全称为Graphical User Interface,叫做图形用户界面,也是一种交互方式(Interaction).早期计算机使用的命令行界面(command-line i ...
- 理解ClassLoader工作机制
package com.ioc; public class Test { public static void main(String[] args) throws ClassNotFoundExce ...
- Oscar的数理统计笔记本
目录 Random Variable discrete distribution: continuous distribution: 统计量 现代统计学时期: Survey sampling Rand ...
- [原]C++新标准之std::chrono::time_point
原 总结 STL 标准库 chrono time_point ratio 概览 类定义 总结 思考 拓展 system_clock steady_clock high_resolution_cloc ...
- 绿洲作业第一周 - 美术Art work
Dear parents, Please remind your child to learn and finish the work as follows from the art teacher: ...