Flash Attributes are not working

2.6k views Asked by At

I have got an Spring MVC project (AppFuse) and Flash attributes are not transmitted to the GET request.

What I do: In the transmitter method:

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Entity entity, BindingResult errors, HttpServletRequest request, HttpServletResponse response, RedirectAttributes ra){
   ...
   ra.addFlashAttribute("id", entity.getId().toString());
   success = "redirect:somePage";
   ...
   return success;
}

In the receiver method, I cannot get the passed flash attribute. I tried these approaches:

  • by ModelMap
  • by Model
  • by @ModelAttribute("id")
1

There are 1 answers

0
JRr On BEST ANSWER

The issue is in the redirecting string. Working one is:

success = "redirect:/somePage";

More correct solution is:

success = "redirect:" + request.getContextPath() + "/somePage";

Double slash redirect is also non-working:

success = "redirect://somePage";