springmvc 异常处理

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 model = new HashMap();
		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" %>



	操作失败



操作失败,${message}

${ex.message}

 

applicationContext.xml

...

 

...

你可能感兴趣的:(工作日志)