Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to another site in Spring MVC JavaEE

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.

like image 561
Cristian Avatar asked Nov 05 '12 00:11

Cristian


1 Answers

Here is one way to do it:

@RequestMapping(value = "/redirectTravelocity", method = RequestMethod.GET)
private String processForm()
{
    return "redirect:http://stackoverflow.com";
}
like image 158
Matt Avatar answered Nov 14 '22 22:11

Matt