title: fetching json object by ajax in jsp
body: <p>guys i am new so please help me .. i am trying to fetch a json data by using jqyery ajax in jsp .. but it is not working .. undefined appears .. here is my code
  in servlet</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      JSONObject json = null;
      PrintWriter pw = response.getWriter(); 
  
      try {
          json = new JSONObject();
          json.put("key1", "value1");
          json.put("key2", "value2");
          json.put("key3", "value3");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      response.setContentType("application/json");
      response.setCharacterEncoding("UTF-8");
      pw.print(json.toString());
      pw.close(); 
  }
  </code></pre>
  
  <p>in jsp </p>
  
  <pre><code>$(document).ready(function(){
      $.ajax({
  
          url : 'Server',
          type: 'POST',
          dataType : 'json',
          error : function(that,e) {
  
              console.log(e);
          },
          success : function(data) {
              alert(data.json);
          }
      });
  
  });
  </code></pre>