Issue
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 ?
Solution
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.
Answered By - Bozho