0
@Controller
@RequestMapping(value="core/*")
public class CoreController {
public static String exceptionOccurredView = "/core/exceptionOccurred";
@ExceptionHandler(Throwable.class)
public ModelAndView exceptionOccurred(Throwable exception, HttpServletResponse response, HttpServletRequest request) {
ModelAndView mv = new ModelAndView();
mv.setViewName (exceptionOccurredView);
mv.addObject ("requestedUrl", Core.getCurrentUrlWithParams());
mv.addObject ("exception", exception);
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Core.getCurrentUrlWithParams());
return mv;
}
@RequestMapping
public void test0(HttpServletResponse response, HttpServletRequest request) throws IOException {
throw new IOException();
}
}
的正常工作核心URL下存在的所有產生的異常。
如果我去的URL
本地主機:8080 /核心/ TEST0
錯誤頁面顯示。另外,如果我去:
本地主機:8080 /核心/ actionDoesNotExist
,但如果我使用:
本地主機:8080/controllerDoesNotExist/TEST0
的錯誤沒有得到因爲註釋@ExceptionHandler僅對每個控制器有效。
那麼如何實現一個全局的,非控制器附加的異常/錯誤處理程序?
是否有可能不呈現一個視圖,但重定向到一個控制器/動作的一些prepropccessing? – momomo 2012-04-04 13:45:08
我猜你必須創建你自己的HandlerExceptionResolver實現..謝謝! – momomo 2012-04-04 13:49:13
我很快就接受了你的答案,經過測試,得到了同樣的結果:( – momomo 2012-04-04 14:07:12