我想用@exceptionhandler捕捉HTTP狀態500 - 預期會話屬性。我想返回一條消息給我向用戶顯示錯誤的同一頁面。使用用SpringMVC HTTP @ExceptionHandler狀態500 - 預期會話屬性
有人可以指點我如何處理這個異常,並返回一個消息到視圖,而不是重定向到另一個頁面的例子。
這是我迄今爲止,但視圖中的項目沒有得到與錯誤消息設置;
@ExceptionHandler(HttpSessionRequiredException.class)
public RedirectView handleHttpSessionRequiredException(Exception ex, HttpServletRequest request) throws Exception
{
logger.info("In the handleHttpSessionRequiredException Handler Method");
String referrer = request.getHeader("referer");
RedirectView redirectView = new RedirectView(referrer);
redirectView.addStaticAttribute("errorMessage","Execute A Query Then Retry");
return redirectView;
}
查看
<label id="errorMessage" name="errorMessage">${errorMessage}</label>
我認爲你可以做的就是檢查屬性是否爲null拋出一個你可以在@ExceptionHandler中捕獲的異常,然後通過添加的消息回到相同的視圖。看到這個https://github.com/SpringSource/spring-mvc-showcase/tree/master/src/main/java/org/springframework/samples/mvc/exceptions和http://stackoverflow.com/questions/2757198/ – apurvc 2013-05-03 05:49:45