Java Spring MVC 3.1重定向属性不工作
我试图在SpringMVC3.1版本中实现重定向属性特性 我正在向Post URL发送简单表单,并希望看到我在重定向中发送的值: 我的控制器如下所示:Java Spring MVC 3.1重定向属性不工作,java,spring,jakarta-ee,spring-mvc,Java,Spring,Jakarta Ee,Spring Mvc,我试图在SpringMVC3.1版本中实现重定向属性特性 我正在向Post URL发送简单表单,并希望看到我在重定向中发送的值: 我的控制器如下所示: @Controller public class DefaultController { @RequestMapping(value="/index.html", method=RequestMethod.GET) public ModelAndView indexView(){ ModelAndView mv
@Controller
public class DefaultController {
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView indexView(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
@RequestMapping(value="/greetings.action", method=RequestMethod.POST)
public ModelAndView startTask(@RequestParam("firstName") String firstName,RedirectAttributes redirectAttributes){
redirectAttributes.addFlashAttribute("redirectAttributes.firstName", firstName);
ModelAndView mv = new ModelAndView(new RedirectView("success.html"));
return mv;
}
@RequestMapping(value="/success.html", method=RequestMethod.GET)
public ModelAndView successView(){
ModelAndView mv = new ModelAndView("success");
return mv;
}
}
现在,我的Servlet XML如下所示:
@Controller
public class DefaultController {
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView indexView(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
@RequestMapping(value="/greetings.action", method=RequestMethod.POST)
public ModelAndView startTask(@RequestParam("firstName") String firstName,RedirectAttributes redirectAttributes){
redirectAttributes.addFlashAttribute("redirectAttributes.firstName", firstName);
ModelAndView mv = new ModelAndView(new RedirectView("success.html"));
return mv;
}
@RequestMapping(value="/success.html", method=RequestMethod.GET)
public ModelAndView successView(){
ModelAndView mv = new ModelAndView("success");
return mv;
}
}
/
.jsp
我的问题是,在success.html视图中,重定向属性为空
<body>
<h5>${redirectAttributes.firstName} </h5>
</body>
${redirectAttributes.firstName}
不打印任何内容。看起来您需要从密钥名称中删除“redirectAttributes.” 而不是:
redirectAttributes.addFlashAttribute("redirectAttributes.firstName", firstName);
这样做:
redirectAttributes.addFlashAttribute("firstName", firstName);
它不起作用,因为您使用ModelAndView作为返回值
参见JIRA问题:我也有同样的问题。如果你得到了解决方案,请告诉我。是的,我有。我在我的社区网站上写了一些关于它的想法,希望它能帮助你。Tks Danny。我在循环同样的问题。关键是返回一个字符串而不是ModelAndView,看起来很奇怪,但可以工作。嗨,无论是否使用此pref,它都可以完美工作ix在密钥名中。