title: READ JSON String in servlet
body: <p>I am posting a jQuery AJAX POST to a servlet and the data is in the form of JSON String.
  Its getting posted successfully but on the Servlet side I need to read these key-val pairs into a Session Object and store them. I tried using JSONObject class but I am not able to get it.</p>
  
  <p>Heres the code snippet</p>
  
  <pre><code>$(function(){
     $.ajax(
     {
        data: mydata,   //mydata={"name":"abc","age":"21"}
        method:POST,
        url: ../MyServlet,
        success: function(response){alert(response);
     }
  });
  </code></pre>
  
  <p>On the Servlet side</p>
  
  <pre><code>public doPost(HTTPServletRequest req, HTTPServletResponse res)
  {
       HTTPSession session = new Session(false);
       JSONObject jObj    = new JSONObject();
       JSONObject newObj = jObj.getJSONObject(request.getParameter("mydata"));
       Enumeration eNames = newObj.keys(); //gets all the keys
  
       while(eNames.hasNextElement())
       {
           // Here I need to retrieve the values of the JSON string
           // and add it to the session
       }
  }
  </code></pre>