I am handling forms in Spring MVC and I submitted a form and I am trying to redirect the post request to avoid resubmitting the form with refresh button.
But I need a dynamically generated value to be displayed based on the form submission in the redirected page. So I am saving that value in session in the post handler method and getting it back in the redirected page handling method.
Would I get the session attribute shown displayed in the redirected page like request parameters in GET method case?
Following is the code that I am using:
This method is handling the form submission
@RequestMapping(value="/something", method=RequestMethod.POST)
public String testStopped(Model model, WebRequest request, HttpSession session) {
//...
int foo = 1234;//some dynamically generated value
session.setAttribute("foo", foo);
return "redirect:/something/somethingelse";
}
This method is handling the redirected page
@RequestMapping(value="/something/somethingelse")
public String testStopped(Model model, HttpSession session) {
...
Integer kungfoo = (Integer) session.getAttribute("foo");
model.addAttribute("kungfoo", kungfoo);
return "somethingelse";
}
This is the url I end up with after redirect: http://wikedlynotsmart.com/something/somethingelse?kungfoo=1234
Is there a way to for ?kungfoo=1234
not to be displayed at the end and still get it passed to the redirect request handler method?
Is this how it is supposed to work or I am committing a blunder somewhere? Could someone help me understand it?
Thanks.