title: Ajax call to servlet through jQuery and response printing
body: <p>I want to make a ajax call to servlet and print the response. 
  I have written <code>index.html</code>,  <code>Assignemnt</code> servlet and <code>web.xml</code> as follows, but I am not getting the alert. What is going wrong?</p>
  
  <p><code>index.html</code></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;
      &lt;script&gt;
      $(document).ready(function() {
          $("button").click(function() {
              $.get("Assignment", function(data, status) {
                  alert("Data: " + data + "\nStatus: " + status);
              });
          });
      });
  &lt;/script&gt;
  
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="GET" action="Assignment" name="showall"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="id1" /&gt;&lt;/td&gt;
                  &lt;td&gt;Jim&lt;/td&gt;
                  &lt;td&gt;Knopf&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="id2" /&gt;&lt;/td&gt;
                  &lt;td&gt;Jim&lt;/td&gt;
                  &lt;td&gt;Bean&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
  
  
          &lt;p&gt;
              &lt;button&gt;Send an HTTP GET request to a page and get the
                  result back&lt;/button&gt;
          &lt;/p&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Servlet:</p>
  
  <pre><code>protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          System.err.println("-------++++");
          String data = "Hello World!";
          response.setContentType("text/plain");
          response.setCharacterEncoding("UTF-8");
          response.getWriter().write(data);
          //RequestDispatcher rd = request.getRequestDispatcher("/Assignment");
          RequestDispatcher rd = request.getRequestDispatcher("/index.html");
          rd.forward(request, response);
  
      }
  </code></pre>
  
  <p>Servlet mapping:</p>
  
  <pre><code> &lt;servlet&gt;
      &lt;description&gt;FirstAssignment&lt;/description&gt;
      &lt;display-name&gt;Assignment&lt;/display-name&gt;
      &lt;servlet-name&gt;Assignment&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.Assignment&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Assignment&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/Assignment&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>