Reputation: 19
How to programmatically forward from one method in a controller to another method using spring mvc 3.0
@RequestMapping(value = "getData", method = RequestMethod.POST)
public void getData(@RequestBody LazyTreeGridInput lazyTreeGridInput,
HttpServletResponse response){
if(someCondition){
//forward to getParents
}else{
//forward to children
}
}
Upvotes: 1
Views: 10476
Reputation: 303
if (someCondition) {
return "redirect:/parentsUrl";
} else {
return "redirect:childUrl";
}
Upvotes: 1
Reputation: 1
Try returning a String instead, and the String being the forward url.
@RequestMapping({"/getData"})
public String execute(Model model) {
if (someCondition) {
return "forward:/parentsUrl";
} else {
return "forward:/childUrl";
}
}
Upvotes: 0
Reputation: 2896
Why not put the other controller's url in the modelAndView which your handler method returns? Does calling the controller method directly the same as forwarding it?
Upvotes: 0
Reputation: 42849
You can see here various ways to redirect using spring mvc 3.0.
UPDATE:
If you are more interested in forwarding, you should make your controllers available in this controller, and just call the method you wish to forward to.
Upvotes: 2