title: How to receive response from servlet to jsp as ajax json response
body: <p>I send ajax request to servlet and servlet is giving the json object. But in ajax response, i did not receive the josn response . I put alert and log method to check the response comes to success method.But i did not even get the alert / log .</p>
  
  <p>Jsp Ajax request/response:</p>
  
  <pre><code> $(document).ready(function() {
            $("#searchCntrBtn").click(function(event) {
              event.preventDefault();
              $.ajax({
                  type: 'GET',
                  dataType: "json",
                  url: '/&lt;%=si.webContext%&gt;/servlet/webAdmin.WebAdminGetCntrDetailsServlet',
                  success: function(data) 
                  {
                      var json = JSON.parse(data);
  
                      console.log("success", json);
                     // $('#myModal').show();
                     // $('#modalContent').show().html(data);
                  }
              });
            })
          })
  </code></pre>
  
  <p>Servlet :-</p>
  
  <pre><code>response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            String jsondata = new Gson().toJson(cntrs);
  
           // out.write(json);
            response.getWriter().write(jsondata);
  
            out.print(jsondata);
            System.out.println("JSON data----&gt;"+jsondata);
            out.flush();
  </code></pre>
  
  <p>Not sure what went wrong here but response is not reaching to the success function in jsp. Can you guys please help me on this . thanks in advance.</p>