1.定义全局异常处理器,为全局的异常,如出现将调用 error.JSP
error
@RequestMapping("hello.do") public String excute(@ModelAttribute("username") String username,String pwd,Model model){ model.addAttribute("name","TOM"); //有可能抛出异常 String s = null; s.length(); return "hello"; }
2.定义局部异常处理,Controller里面的请求捕获
//局部异常处理,当前Controller发生错误调用dateerror.jsp @ExceptionHandler public String handleException( HttpServletRequest request, Exception ex){ request.setAttribute("error", ex); return "dateerror"; }