I am using UrlBasedViewResolver. My requirement is that two different URls talk to same controller and they should go to two different pages aka page1 or page2 based on the URL.
These two pages have same model object, they are almost same except few minor UI changes. How can this be achieved neatly in Spring MVC.
@RequestMapping(value = {"/page1","/page2"}, method=RequestMethod.GET)
public String displayPage(ModelMap map){
// return to Page1 or Page2 accordingly wherever it came from
}
@RequestMapping(value = {"/page1","/page2"}, method=RequestMethod.POST)
public ModelAndView submitPage(@ModelAttribute("model") Model model){
return new ModelAndView("page1 or page2", "command", model);
}
One option:
Another:
Second option might have some issues depending on your controller mappings, and some potential security concern due to trying to return view based on incoming URL.