8 April 2011

How to redirect to other controller in spring 3 (that

Solution for spring 3.0.x:

You controller done his job less or more successfully and now you will would love to share your data with other controller to do his job.
What you need to is simply on return you need add redirect:  (with path) for example:
      return "redirect:/secretpage/lollypop.html";

so your controller will looks :

public class SecretController {
  (... some private pleasue or business logic ...)

@RequestMapping(method = RequestMethod.POST)
  public String processForm(HttpSession session, HttpServletResponse response,@Valid SecretForm secretForm, BindingResult result)  Model model) {
(... your private pleasue or business logic   ...)
       return "redirect:/secretpage/lollypop.html";

what happen ?
SecretController will send view to client and say "Hello folk! This is view,but can you go to this page ( (page)/secretpage/lollypop.html ",please? Client will answer "no problem" and send request to dispatcher with question "any idea what to do with this ?" and then other spring stuff happen.

No comments:

Post a comment