title: request.getParameter() returns null when using $.ajax with JSON object as data
body: <p>I'm learning Java servlets and I wrote two separate servlets for "GET" and "POST". When a "GET" request is sent to the server, the servlet accesses the database and retrieves everything and converts the result to the format that can be recognized by Google Charts. And when a "POST" request is sent to the server, the servlet gets the parameters and adds them to a Java object and then the DAO adds the data to the database. However, when I hit the "add" button after the input, the web app cannot find the servlet at all. It simply just "skips" the ajax function and proceeds. So here's the servlet that does the insertion:</p>
  
  <pre><code>@WebServlet("/InsertServlet")
  public class InsertServlet extends HttpServlet 
  {
      private static final long serialVersionUID = 1L;
      private EmployeeDao dao;
  
      public InsertServlet() throws SQLException 
      {
          super();
          dao = new EmployeeDao();
      }
  
      public void doPost(HttpServletRequest request, HttpServletResponse response) 
              throws ServletException, IOException 
      {
          System.out.println("doPost");
          Employee e = new Employee();
          e.setName(request.getParameter("name"));
          e.setSSN(request.getParameter("ssn"));
          e.setDob(request.getParameter("birth"));
          e.setIncome(request.getParameter("xxxx"));
  
          dao.addEmployee(e);
  
          response.setContentType("text/html;charset=utf-8");
          PrintWriter out = response.getWriter();
          out.println("&lt;h2&gt;Data Entry Added&lt;/h2&gt;&lt;br&gt;");
          out.println("&lt;h2&gt;"+request.getParameter("name")+"&lt;/h2&gt;");
          out.println("&lt;h2&gt;"+request.getParameter("ssn")+"&lt;/h2&gt;");
          out.println("&lt;h2&gt;"+request.getParameter("birth")+"&lt;/h2&gt;");
          out.println("&lt;h2&gt;"+request.getParameter("xxxx")+"&lt;/h2&gt;");
          out.flush();
          out.close();
  
  
      }
  }
  </code></pre>
  
  <p>And here's the index.html:</p>
  
  <pre><code>&lt;form id="inputForm"&gt;
  &lt;table style="width:80%;border:3px;"&gt;
      &lt;tr&gt;
          &lt;td align="center"&gt;&lt;input type="text" name="name" id="name" placeholder="First Last"&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" name="ssn" id="ssn" placeholder="111111111"&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" name="birth" id="birth" placeholder="MM/DD/YYYY"&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" name="xxxx" id="xxxx" placeholder="12345"&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;button type="button" name="add" id="add" &gt;Add&lt;/button&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;button type="button" name="delete" id="delete"&gt;Delete&lt;/button&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  $("#add").click(function() {
              var nameIn = $('#name').val();
              var ssnIn = $('#ssn').val();
              var birthIn = $('#birth').val();
              var xxxxIn = $('#xxxx').val();
              if (validate(nameIn, ssnIn, birthIn, xxxxIn) === true) {
                  xxxxIn = "\$" + xxxxIn;
                  var ssn1 = ssnIn.substring(0, 3);
                  var ssn2 = ssnIn.substring(3, 5);
                  var ssn3 = ssnIn.substring(5);
                  ssnIn = ssn1 + '-' + ssn2 + '-' + ssn3;
  
                  $.post("InsertServlet", $("#inputForm").serialize(), function(responseHtml) {
                      $('#state').html(responseHtml);
                  });
                  window.setTimeout(redraw, 1000);
                  redraw();
              }
          });
  </code></pre>
  
  <p>Edit 1: So the web app works all the way to the point where the $ajax of "add" sends the proper request. The JS functions worked fine. The request has the correct values corresponding to the attributes. However, when invoking the /InsertServlet URL, it seems that the web app just ignores the servlet and the getParameter methods all return null in the doPost method. </p>
  
  <p>Edit 2: Tomcat version: 7.0.61. JDK version: 1.7.0_45. Servlet version: 3.0</p>