我想有以下方法執行重定向:從Spring MVC的@ExceptionHandler方法
@ExceptionHandler(MyRuntimeException.class)
public String myRuntimeException(MyRuntimeException e, RedirectAttributes redirectAttrs){//does not work
redirectAttrs.addFlashAttribute("error", e);
return "redirect:someView";
}
我得到一個:
java.lang.IllegalStateException: No suitable resolver for argument [1] type=org.springframework.web.servlet.mvc.support.RedirectAttributes]
是否有從@ExceptionHandler
執行重定向的方式?或者,也許有某種方法來規避這種限制?
編輯:
我已經修改了我的異常處理程序如下:
@ExceptionHandler(InvalidTokenException.class)
public ModelAndView invalidTokenException(InvalidTokenException e, HttpServletRequest request) {
RedirectView redirectView = new RedirectView("signin");
return new ModelAndView(redirectView , "message", "invalid token/member not found");//TODO:i18n
}
這是可能拋出異常的方法:用我的修改
@RequestMapping(value = "/activateMember/{token}", method = RequestMethod.GET, produces = "text/html")
public String activateMember(@PathVariable("token") String token) {
signupService.activateMember(token);
return "redirect:memberArea/index";
}
問題異常處理程序是它系統地將我重定向到以下URL:
http://localhost:8080/bignibou/activateMember/signin?message=invalid+token%2Fmember+not+found
相反的:
http://localhost:8080/bignibou/signin?message=invalid+token%2Fmember+not+found
編輯2:
這裏是我的修飾處理方法:
@ExceptionHandler(InvalidTokenException.class)
public String invalidTokenException(InvalidTokenException e, HttpSession session) {
session.setAttribute("message", "invalid token/member not found");// TODO:i18n
return "redirect:../signin";
}
的問題我現在是該消息被卡住在會議...
你有沒有找到一個不添加查詢字符串參數的解決方案? – mericano1 2013-04-10 12:17:23
不幸的是沒有。 – balteo 2013-04-10 14:08:42