Spring MVC- Redirect from one controller to another
In spring mvc its very easy to redirect from one controller to another controller
Example :
@Controller
@RequestMapping("/springcontroller1")
public class SpringController1{
}
@Controller
public class SpringController2{
//thinking of redirecting on clicking on a method
@RequestMapping(value = "/SpringController2cancel.abc", method = RequestMethod.POST, params = "action=cancel")
public ModelAndView cancel(@ModelAttribute("MyForm") MyForm myForm, BindingResult errors,SessionStatus sessionStatus,HttpServletRequest request) throws MyException {
ModelAndView modelAndView = new ModelAndView();
sessionStatus.setComplete();
//redirecting to controller1
return new ModelAndView("redirect:/springcontroller1.abc");
}
}
Example :
@Controller
@RequestMapping("/springcontroller1")
public class SpringController1{
}
@Controller
public class SpringController2{
//thinking of redirecting on clicking on a method
@RequestMapping(value = "/SpringController2cancel.abc", method = RequestMethod.POST, params = "action=cancel")
public ModelAndView cancel(@ModelAttribute("MyForm") MyForm myForm, BindingResult errors,SessionStatus sessionStatus,HttpServletRequest request) throws MyException {
ModelAndView modelAndView = new ModelAndView();
sessionStatus.setComplete();
//redirecting to controller1
return new ModelAndView("redirect:/springcontroller1.abc");
}
}
What is springcontroller1.abc is all about (abc?)
ReplyDeleteThanks for your great information, the contents are quiet interesting.I will be waiting for your next post.
ReplyDeleteWindow Ac Repairing Service in Delhi NCR
This was a useful post and I think it's fairly easy to see in the other reviews, so this post is well written and useful. Keep up the good work.
ReplyDeleteBuilding Contractors Service Provider In Delhi NCR
This turned into a beneficial post and I suppose it is fairly clean to see inside the other opinions, so this put up is properly written and useful. Keep up the good work buy persuasive essay in uk
ReplyDeleteThis is such a great resource that you are providing and you it away for free. I love seeing blog that understand the value.
ReplyDeleteEvent Organizers in South Delhi
Event Organizers in Delhi NCR