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");


    }

}

Comments

  1. What is springcontroller1.abc is all about (abc?)

    ReplyDelete

Post a Comment

Popular posts from this blog

Integrating Struts2 with Spring Security using Custom Login Form