predhme predhme - 5 months ago 29
Java Question

Spring MVC Controller redirect using URL parameters instead of in response

I am trying to implement RESTful urls in my Spring MVC application. All is well except for handling form submissions. I need to redirect either back to the original form or to a "success" page.

@Controller
@RequestMapping("/form")
public class MyController {

@RequestMapping(method = RequestMethod.GET)
public String setupForm() {
// do my stuff
return "myform";
}

@RequestMapping(method = RequestMethod.POST)
public String processForm(ModelMap model) {
// process form data

model.addAttribute("notification", "Successfully did it!");
return "redirect:/form";
}
}


However as I read in the Spring documentation, if you redirect any parameters will be put into the url. And that doesn't work for me. What would be the most graceful way around this?

Answer Source

http://jira.springframework.org/browse/SPR-6464 provided me with what I needed to get things working until Spring MVC offers the functionality (potentially in the 3.0.2 release). Although I simply implemented the classes they have temporarily and added the filter to my web application context. Works great!