springspring-mvcappfuse

Flash Attributes are not working


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:


Solution

  • 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";