url:http://cgs1999.iteye.com/blog/1547197
本人用的是springSide ,Dao层用的是springdata 没有显示抛出异常
异常类
public class myExceptionResolver implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("ex", ex);
// 根据不同错误转向不同页面
if (ex instanceof DataIntegrityViolationException) {
model.put("message", "违反完整性约束");
return new ModelAndView("/error/error", model);
} else if (...) {
return new ModelAndView("...", model);
} else {
return new ModelAndView("/error/500", model);
}
}
}
页面
<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>操作失败</title>
</head>
<body>
<center>
<div style="width:100%">
<p>操作失败,${message}</p>
<div style="width:70%;display:none">${ex.message}</div>
</div>
<div><a href="javascript:void(0);" οnclick="history.back()">返回</a></div>
</center>
</body>
</html>
applicationContext.xml
...
<bean id="exceptionHandler" class="com.hymake.bobing.util.BobingExceptionResolver"/>
...