Tiles and Redirection in Spring MVC

I use Tiles 2 in my Spring 3 MVC application i defines the 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, REDIRECT does not work.

Any idea how to redirect after a successful POST using Tiles?

thanks

EDIT: The solution is to add this to views.properties:

 redirectcompanylist.(class)=org.springframework.web.servlet.view.RedirectView redirectcompanylist.url=/companylist.htm 

And return the redirectcompanylist to the controller

+4
source share
1 answer

When redirecting you will have to use the URL path. Example: return redirect:/companylist.htm , which then jumps to the corresponding method in the controller.

+4
source

All Articles