Spring mvc redirect to a page from formBackingObject()
I am using Spring MVC 2.5. I want to redirect to a url from
formBackingObject(HttpServletRequest request)
method used in a spring controller.
As there is no ModelAndView object in this method; also I created response object bur it di开发者_开发百科d not work as well.
HttpServletResponse response = null;
response.sendRedirect("google.com");
How can I do that?
You need to override HandleRequest method. Sample code:
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, Exception {
if (condition) {
return new ModelAndView("downloadInProgress");
}else{
return super.handleRequest(request,response);
}
}
formBackingObject() will run complete and will not redirect. In controller handleRequest() method can do it.
In yr controller do this:
public String method(){
return "redirect:http://google.com"
}
Also asked before here btw.
精彩评论