开发者

Spring mvc redirect to a page from formBackingObject()

开发者 https://www.devze.com 2023-04-02 07:02 出处:网络
I am using Spring MVC 2.5. I want to redirect to a url from formBackingObject(HttpServletRequest request) method used in a spring controller.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号