title: Performing a normal redirect from an ajax Spring MVC controller method
body: <p>I have a Spring MVC controller method. </p>
  
  <p>I would like for this method to:</p>
  
  <ul>
  <li>return a JSon @ResponseBody (in ajax) if there are validation errors</li>
  <li>perform a normal redirect to a given URL if there are no validation errors</li>
  </ul>
  
  <p>Assuming I have a javabean object called myObject, I tried the following:</p>
  
  <pre><code>@RequestMapping(value = "/new", method = RequestMethod.POST)
  @ResponseBody
  public MyJavabeanObject myMethod(@RequestBody MyJavabeanObject myObject, BindingResult bindingResult, Model model,
          RedirectAttributes redirectAttributes, HttpServletResponse response) throws IOException {
  
      if (bindingResult.hasErrors()) {
          //adding error message to javabean
          return myObject;
      }
  
      response.sendRedirect("/success");
      return null;
  }
  </code></pre>
  
  <p>Can anyone please let me know if what I am trying to achieve is at all possible?</p>