如何将数据发送到重定向的URL spring mvc

Fel*_*sso 3 redirect servlets response spring-mvc request

我有一个URL,在调用时会重定向到另一个URL.我想传递一些数据和重定向.

例如,我有这个方法:

@RequestMapping("efetuaEnvioEmail")
    public String efetuaEnvioEmail(HttpServletResponse response) throws IOException {
        System.out.println("efetuaEnvioEmail");
        return "redirect:inicio";
    }
Run Code Online (Sandbox Code Playgroud)

哪个重定向到这个:

@RequestMapping("inicio")
    public String Inicio(HttpServletRequest request) throws IOException {

        return "Inicio";
    }
Run Code Online (Sandbox Code Playgroud)

我想传递一些数据,告知第一种方法一切正常.

我已经尝试了HttpServletRequest和HttpServletResponse的一些方法,但我没有任何东西.

Pav*_*ral 5

用于RedirectAttributes在处理程序方法之间传递任何数据:

@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";
}
Run Code Online (Sandbox Code Playgroud)