title: No data returned from $.getJSON() (JSP, Servlet, jQuery Ajax)
body: <p>I am trying to learn jQuery Ajax with JSP, Servlets and JDBC.</p>
  
  <p>What all am trying:
  I have two text boxes in JSP.
  When I type in something in first one and hit Tab, on its blur event I make getJson() call to a servlet which in turn calls a JDBC handler (which I have tested independently and is working fine hence not included here). In servlet, I am setting content type, converting data retrieved from JDBC to Json using Gson library and returning it.</p>
  
  <p>The main problem is that when I hit tab and textbox's onblur event invokes it executes getJson but the servlet is not getting executed since in eclipse I have put println() in Servlet. It does not prints anything on eclipse console. Is it supposed to put anything on console(, since it is getting called from JS)? because no data is returned from Servlet the callback success function in getJson is also not getting executed (I confirmed that in IE F12 tools and also by puting alert in it). </p>
  
  <p><strong>My JSP</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01          
   Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;  
  &lt;head&gt;      
      &lt;script type="text/javascript" src="scripts/jquery-1.9.0.min.js"&gt;&lt;/script&gt;
  
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;script&gt;
          function doTransact()
          {
              $.getJSON('AjaxController?text='+$("#inText").val(),
                          function(data)
                          {   
                                  //alerting to check whether callback function is in 
                                  //fact getting called or not
                              alert(data.text);
                                  $("#outText").valdata.text);
                              }
                      );
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      Type here:&lt;input onblur="doTransact();" type="text" id="inText"&gt;&lt;/input&gt;
      &lt;br /&gt;
      Get here:&lt;input type="text" id="outText"&gt;&lt;/input&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>For responding to getJSON request I written following AjaxController servlet and added:</p>
  
  <pre><code>package com.exp.controller;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.exp.dao.AjaxDAO;
  import com.google.gson.Gson;
  
  public class AjaxController extends HttpServlet 
  {   
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
      {
          System.out.println("done");
          response.setContentType("application/json");
  
          AjaxDAO adao = new AjaxDAO();
  
          String text = adao.setGetText(request.getParameter("text"));
  
          //printing on console to check whether Servlet is in fact gettiing called or not
          System.out.println("In Ajax Controller");
  
          if(text!=null)
          {
              PrintWriter out = response.getWriter();
  
              String convertedJson = new Gson().toJson(text);
              out.println(convertedJson);
          }
  
      }
  
  }
  </code></pre>
  
  <p>I have configured web.xml correctly what could be the reason for AjaxController not getting called? Can anyone spot it? Or am I doing it in wrong way? And also is this way good practice or I should follow some other approach?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is how debug time view looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/ddq1B.png" alt="enter image description here"></p>