6

I've been googling a while and I couldn't find a clear answer or documentation about this specific method.

I want to redirect to another site, like stackoverflow.com using this method... But I don't know how to do it. Any help will be appreciated.

@RequestMapping(value = "/redirectTravelocity", method = RequestMethod.GET)
private ModelAndView processForm()
{
    ModelAndView modelAndView = new ModelAndView( "redirect:stackoverflow.com" );
    Map<String, Object> model = modelAndView.getModel();

    model.put( "error", "this.is.my.error.code" );
    return new ModelAndView( "redirect:stackoverflow.com", model );
}

It doesn't work, it redirects within my site and it crashes... I know this is stupid but I don't know how to do it.

2 Answers 2

7

Here is one way to do it:

@RequestMapping(value = "/redirectTravelocity", method = RequestMethod.GET)
private String processForm()
{
    return "redirect:http://stackoverflow.com";
}
1
  • Maybe another option is to set the HttpResponse header and set the return type to void. something like: @RequestMapping(value = "/redirectTravelocity", method = RequestMethod.GET) private void processForm(HttpServletResponse response) { response.setRedirectUrl("xxx"); }
    – Edmond
    Jan 14, 2014 at 8:01
0

change redirect:stackoverflow.com to redirect:http://stackoverflow.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.