1

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")
JRr
  • 1,552
  • 1
  • 19
  • 23
  • Are you using Model in the receiver method? See http://stackoverflow.com/a/11763834/65681 – Matt Raible Jun 20 '15 at 02:26
  • I tried using Model in the receiver method, but it did not work. I also tried with ModelMap, but that did not solved the issue, nor @ModelAttribute.The key was to place single slash in redirect path (making the path absolute). Nothing else helped me. After adding the slash, all 3 approaches started working. – JRr Jun 21 '15 at 12:44

1 Answers1

0

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";
JRr
  • 1,552
  • 1
  • 19
  • 23