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);" onclick="history.back()">返回</a></div>
</center>
</body>
</html>
applicationContext.xml
...
<bean id="exceptionHandler" class="com.hymake.bobing.util.BobingExceptionResolver"/>
...
本文详细介绍了如何在使用SpringSide框架时,通过实现自定义异常解析器来捕获并处理特定异常,并根据不同类型的异常跳转到相应的错误页面。同时,展示了错误页面如何呈现异常信息及提供返回上一页的功能。
129

被折叠的 条评论
为什么被折叠?



