KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Spring 3 MVC Handle multiple form submit with a Controller. I am developing JSP page with multiple forms. 1) Search Customer, 2) Search Product, 3) Print Something etc. I've a different form bind object tied to each form and my controller code looks similar to below @Controller @RequestMapping(value="/search.do") public class SearchController { @RequestMapping(method = RequestMethod.GET) public String pageLoad(ModelMap modelMap) { modelMap.addAttribute("productSearch", new ProductSearchCriteria()); modelMap.addAttribute("customerSearch", new CustomerSearchCriteria()); modelMap.addAttribute("print", new PrintForm()); } @RequestMapping(method = RequestMethod.POST) public ModelAndView searchProducts(@ModelAttribute("productSearch") ProductSearchCriteria productSearchCriteria, BindingResult result, SessionStatus status) { //Do Product search return modelAndView; } @RequestMapping(method = RequestMethod.POST) public ModelAndView searchCustomers(@ModelAttribute("customerSearch") CustomerSearchCriteria customerSearchCriteria, BindingResult result, SessionStatus status) { //Do Customer search return modelAndView; } @RequestMapping(method = RequestMethod.POST) public ModelAndView printSomething(@ModelAttribute("print") PrintForm printForm, BindingResult result, SessionStatus status) { //Print something return modelAndView; } } Above certainly doesn't work as I assumed it would. I get exception saying 'Request method 'POST' not supported' . If I have only one POST method inside above controller say searchProducts it works well. But it won't with more than one methods with POST. I also tried adding hidden parameter in JSP and changing method signatures similar to below only to get the same exception again. @RequestMapping(
Tags (comma-separated)
Save Edits
Cancel