I have an URL which redirects to another URL when called. I would like to pass some data along with the redirection.
For example I have this method:
@RequestMapping("efetuaEnvioEmail")
public String efetuaEnvioEmail(HttpServletResponse response) throws IOException {
System.out.println("efetuaEnvioEmail");
return "redirect:inicio";
}
Which redirects to this one:
@RequestMapping("inicio")
public String Inicio(HttpServletRequest request) throws IOException {
return "Inicio";
}
I would like to pass some data informing that everything went fine on the first method.
I have tried some methods of HttpServletRequest and HttpServletResponse but I couldn't have anything.
Use RedirectAttributes
to pass any data between handler methods:
@RequestMapping("efetuaEnvioEmail")
public String efetuaEnvioEmail(RedirectAttributes rattrs) {
rattrs.addAttribute("string", "this will be converted into string, if not already");
rattrs.addFlashAttribute("pojo", "this can be POJO as it will be stored on session during the redirect");
return "redirect:inicio";
}
@RequestMapping("inicio")
public String Inicio(@ModelAttribute("pojo") String pojo) {
System.out.println(pojo);
return "Inicio";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With