Java spring mvc中如何将参数传递到重定向页面

Java spring mvc中如何将参数传递到重定向页面,java,spring,spring-mvc,Java,Spring,Spring Mvc,我写了以下内容: @RequestMapping(value="/logOut", method = RequestMethod.GET ) public String logOut(Model model, RedirectAttributes redirectAttributes) { redirectAttributes.addFlashAttribute("message", "success logout"); System.out.print

我写了以下内容:

@RequestMapping(value="/logOut", method = RequestMethod.GET )
    public String logOut(Model model, RedirectAttributes redirectAttributes)  {
        redirectAttributes.addFlashAttribute("message", "success logout");
        System.out.println("/logOut");
        return "redirect:home.jsp";
    }

如何更改页面
home.jsp
上的代码,我可以编写
${message}
,并查看
“成功注销”
当返回值包含
重定向:
前缀时,
视图解析程序
将此识别为需要重定向的特殊指示。视图名称的其余部分将被视为重定向URL。客户端将向该
重定向URL
发送一个新请求。因此,您需要有一个映射到此URL的处理程序方法来处理重定向请求

您可以编写如下处理程序方法来处理重定向请求:

@RequestMapping(value="/home", method = RequestMethod.GET )
public String showHomePage()  {
    return "home";
}
您可以按照以下方式重新编写
注销
处理程序方法:

@RequestMapping(value="/logOut", method = RequestMethod.POST )
public String logOut(Model model, RedirectAttributes redirectAttributes)  {
    redirectAttributes.addFlashAttribute("message", "success logout");
    System.out.println("/logOut");
    return "redirect:/home";
}
编辑:

您可以在应用程序配置文件中使用此项来避免
showHomePage
方法:

<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
 .....
 xsi:schemaLocation="...
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 ....>

<mvc:view-controller path="/home" view-name="home" />
 ....
</beans>

您是否有映射到句柄
home.jsp的控制器?已正确添加flahs属性。
重定向
使用
位置
标题将302响应发送回客户端。在您的例子中,
Location
将是指向
home.jsp
的一些url。你需要有一个处理程序。你知道吗?它是否重定向到
home.jsp
?它没有处理程序是不真实的?我犯了错误。我想避免使用这种方法。我的viewResolver具有常规配置:class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>/web-INF/pages/.jsp home.jsp是web-INF的兄弟