title: Handling ajax requests with spring
body: <p>Here is my problem, I need to map a AJAX request using spring. Now, I know that I need these two guys:</p>
  
  <p>HttpServletRequest, to get the message the client sent to me and parse it from JSON(most likely) to a Map and HttpServletResponse to put my message to the client.
  What I do not know is the right(simple, concise) way to do that...</p>
  
  <p>Here is a code sample from the springframework site:</p>
  
  <pre><code>/**
   * Normal comments here
   *
   * @@org.springframework.web.servlet.handler.metadata.PathMap("/foo.cgi")
   * @@org.springframework.web.servlet.handler.metadata.PathMap("/baz.cgi")
   */
  public class FooController extends AbstractController {
  
      private Cruncher cruncher;
  
      public FooController(Cruncher cruncher) {
          this.cruncher = cruncher;
      }
  
      protected ModelAndView handleRequestInternal (
              HttpServletRequest request, HttpServletResponse response) throws Exception {
          return new ModelAndView("test");
      }
  }
  </code></pre>
  
  <p>Which is nice. Except that, as far as I can see, I cannot map a URL for each method in that class as I would do with this kind of synchronous request:</p>
  
  <pre><code>@Controller
  @RequestMapping("/test")
  public class ControllerTest {
      @RequestMapping(value = "/test.htm", method = RequestMethod.GET)
      public void showSearchView(Model model) {...}
      ...
  }
  </code></pre>
  
  <p>Can I do something that simple for AJAX requests?</p>