Passing model attribute during redirect in spring MVC and avoiding the same in URL

RedirectAttributes only work with RedirectView, please follow the same

@RequestMapping(value="/Login",method = RequestMethod.POST)
public RedirectView loginValidate(HttpServletRequest req, RedirectAttributes redir){
...

    redirectView= new RedirectView("/foo",true);
    redir.addFlashAttribute("USERNAME",uname);
    return redirectView;
}

Those flash attributes are passed via the session (and are destroyed immediately after being used – see Spring Reference Manual for details). This has two interests :

  • they are not visible in URL
  • you are not restricted to String, but may pass arbitrary objects.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)