views:

33

answers:

1

greetings all I have a post method in a controller, which redirects to a new page I a way such like:

@RequestMapping(method = RequestMethod.POST)
    public String post(HttpServletRequest request) {

        return "redirect:http://www.x.appName.com/myPage";

    }

suppose that the user already has a session before the redirection and I want to encode the new url before redirection to maintain the user session how to do so ?

+4  A: 

You can pass the HttpServletResponse as parameter, and use the encodeRedirectURL(..) method:

String url = "http://www.x.appName.com/myPage";
url = response.encodeRedirectURL(url);
return "redirect:" + url;

But first make sure spring does not do this for you automatically.

Bozho
thanks, but i am not sure if spring does this automatically or not, can anyone expert with spring tell us please ?
sword101
well, try it...
Bozho