title: JSON - Spring MVC : How to post json data to spring MVC controller
body: <p>I have a problem posting JSON data from <code>jsp</code> to <code>controller</code>. Everytime I try I get an ajax error <code>Bad Request</code>. Im so new to JSON and I really don't know what I am doing wrong. I searched and tried some samples I can find in this site but still Im having a problem.</p>
  
  <p>In my controller:</p>
  
  <pre><code>@RequestMapping (method = RequestMethod.POST, headers ={"Accept=application/json"}, value = "/form")
  public String postJournalEntry (@RequestParam ("json") String json, Model model) {
      System.out.println(json);
      return "successfullySaved";
  }
  </code></pre>
  
  <p>In my jsp:</p>
  
  <pre><code>$("#btnPostGlEntry").click(function () {
      var glEntries = '{"glEntries":[{"generalLedgerId":"1"},{"accountId":"4"},{"amount":"344.44"},{"description":"Test Entry"},{"debit":"Yes"}]}';
      $.ajax({
          type: "POST",
          contentType: "application/json",
          dataType: "json",
          url: contextPath + "/generalLedger/journalEntries/form",
          data : JSON.stringify(glEntries),
          success: function(data) {
              alert("Success!!!");
          },
          error: function (jqXHR, textStatus, errorThrown) {
              alert(jqXHR + " : " + textStatus + " : " + errorThrown);
          }
      });
  });
  </code></pre>
  
  <p>NOTE : Im not even sure if my function in my controller is correct. I think my controller and my ajax are wrong. Please help.</p>