How should I add attribute after redirect to a controller
I am just a newbie about Spring.
I am now using @ExceptionHandler to handle all the exception for my web
application. And after I catch the exception, it will go to and error.jsp
page displaying the error message.
I have a ParentController and in that, I have:
@org.springframework.web.bind.annotation.ExceptionHandler(PortalException.class)
public ModelAndView handle(PortalException e, HttpServletRequest
request) {
ModelMap map = new ModelMap();
map.addAttribute("message", e.getMessage());
return new ModelAndView("/error", map);
}
and I have a ErrorControllerextends the ParentController to add the
attributes:
@Controller
public class ErrorController extends ParentSecureController {
@RequestMapping(value = "/error", method = RequestMethod.POST)
@ResponseBody
public String errorHandler(Model model, HttpServletRequest request) {
model.addAttribute("excetpion.message",
request.getParameter("message"));
return "/error";
}
}
In the error.jsp:
<p>Excpetion is: ${exception.message}</p>
When I run my application, I can catch the exception and jump to
error.jsp, but no exception message is display. Anyone can help me to
figure out how to solve it.
No comments:
Post a Comment