Spring MVC 中的平铺和重定向
我在 Spring 3 MVC 应用程序中使用 Tiles 2 我定义了一个表单:
<definition name="addcompany.htm" extends="baseLayout">
<put-attribute name="title" value="Add Company"/>
<put-attribute name="body" value="/WEB-INF/jsp/addcompany.jsp"/>
</definition>
和:
addcompany.(class)=org.springframework.web.servlet.view.tiles2.TilesView
addcompany.url=addcompany.htm
这是我的控制器:
@RequestMapping(value="/addcompany.htm", method=RequestMethod.GET)
public ModelAndView getForm() {
logger.info("Getting form!");
ModelAndView mav = new ModelAndView();
logger.info("Loading form");
Company cmp = new Company();
mav.addObject("company",cmp);
mav.setViewName("addcompany");
return mav;
}
@RequestMapping(value="/addcompany.htm", method=RequestMethod.POST)
public String postForm(@ModelAttribute("company") Company cmp) {
logger.info("post form!");
companyService.saveCompany(cmp);
logger.info("post form");
return "redirect:tiles:companylist"; // How do i redirect?
}
使用 Tiles2,重定向不起作用。
知道如何使用 Tiles 成功 POST 后重定向吗?
谢谢
编辑: 解决方案是将其添加到views.properties中:
redirectcompanylist.(class)=org.springframework.web.servlet.view.RedirectView
redirectcompanylist.url=/companylist.htm
并在控制器中返回redirectcompanylist
I am using Tiles 2 in my Spring 3 MVC application
i defines a form :
<definition name="addcompany.htm" extends="baseLayout">
<put-attribute name="title" value="Add Company"/>
<put-attribute name="body" value="/WEB-INF/jsp/addcompany.jsp"/>
</definition>
and :
addcompany.(class)=org.springframework.web.servlet.view.tiles2.TilesView
addcompany.url=addcompany.htm
And here is my controller :
@RequestMapping(value="/addcompany.htm", method=RequestMethod.GET)
public ModelAndView getForm() {
logger.info("Getting form!");
ModelAndView mav = new ModelAndView();
logger.info("Loading form");
Company cmp = new Company();
mav.addObject("company",cmp);
mav.setViewName("addcompany");
return mav;
}
@RequestMapping(value="/addcompany.htm", method=RequestMethod.POST)
public String postForm(@ModelAttribute("company") Company cmp) {
logger.info("post form!");
companyService.saveCompany(cmp);
logger.info("post form");
return "redirect:tiles:companylist"; // How do i redirect?
}
Using Tiles2, the REDIRECT doesnt work.
Any idea how to redirect after a successful POST using Tiles ?
thanks
EDIT :
Solution is to add this in the views.properties :
redirectcompanylist.(class)=org.springframework.web.servlet.view.RedirectView
redirectcompanylist.url=/companylist.htm
And return redirectcompanylist in the controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重定向时您必须使用 URL 路径。像这样:
return redirect:/companylist.htm
然后转到控制器中相应的方法。You'll have to use the URL path when redirecting. Like this:
return redirect:/companylist.htm
which then goes to the corresponding method in the controller.