0

I met in a case such that i have to redirect a link to an external url from a particular controller.I have tried many cases like

response.sendRedirect(url_location);

also tried something like this

response.setHeader("location",url_location);

tried to send the return type as Model and View too.But nothing works out.Can anyone help me out with it.I've seen many suggest to use sendRedirect and setHeader methods which is not working out in my case.So I would also like to know is there any configurations to be made for using these HTTPServeletResponse's methods.

  • what is that you are getting with response.sendRedirect(url_location); – Count May 16 '14 at 12:19
  • Is this similar to http://stackoverflow.com/questions/17955777/redirect-to-an-external-url-from-controller-action-in-spring-mvc – dinesh028 May 16 '14 at 12:49

3 Answers3

0

you may try this

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public ModelAndView method() {
        return new ModelAndView("redirect:" + redirectUrl);

}

or alternatively

 @RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Location", redirectUrl);
}
Count
  • 1,395
  • 2
  • 19
  • 40
0

How try with

return new ModelAndView("redirect:" + url_location);

OR

return "redirect:" + url_location;
Wundwin Born
  • 3,467
  • 19
  • 37
0
 @RequestMapping(value = "/redirect", method = RequestMethod.GET)
    public ModelAndView method() {
            return new ModelAndView("redirect:" + projectUrl);

    }
dinesh028
  • 2,137
  • 5
  • 30
  • 47