开发者

Tiles and redirect in Spring MVC

开发者 https://www.devze.com 2023-01-25 09:32 出处:网络
I am using Tiles 2 in my Spring 3 MVC application i defines a form : <definition name=\"addcompany.htm\" extends=\"baseLayout\">

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消