title: Java servlet can't get POST params
body: <p>I am trying to create a simple sign in screen that has an email field, a password field, and a sign in button (all three enclosed inside a <code>&lt;form/&gt;</code>). When the user submits the form, the client does an AJAX POST (asynchronous so that the user doesn't have to "suffer" a page reload!) to a servlet. The servlet, for now, just does a dummy check and returns a "1" if the user successfully signed in, or a "0" if the email/password were bad. The client then handles the response (again, will be either 0 or 1).</p>
  
  <p>What's happening is this: when I submit the form, the servlet receives the HTTP POST request, but the email/password fields are showing up as NULL:</p>
  
  <pre><code>public class SigninService extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      @Override
      public void doPost(HttpServletRequest request, HttpServletResponse response) {
          PrintWriter writer = null;
          try {
              writer = response.getWriter();
              JSONSerializer serializer = new JSONSerializer();
  
              System.out.println("\tFetching POST data...");
              String email = request.getParameter("email");
              System.out.println("\tEmail is " + email + "...");
              String password = request.getParameter("password");
              System.out.println("\tPassword is " + password + "...");
  
              Integer answer = null;
              // Dummy check; will replace with actual code once I get this example working...
              if("testing@example.com".equals(email) &amp;&amp; "12345".equals(password))
                  answer = 1;
              else
                  answer = 0;
  
              System.out.println("\tSerializing the HTTP response...");
              String json = serializer.deepSerialize(answer);
  
              System.out.println("\tSending response back to client...");
              writer.write(json);
          } catch (Throwable throwable) {
              System.err.println(throwable.getMessage());
              throwable.printStackTrace();
          } finally {
              writer.close();
          }
      }
  }
  </code></pre>
  
  <p>The above code prints <code>null</code> values for both email/password. I read several articles on extracting POST data from <code>HttpServletRequest</code> (notably <a href="https://stackoverflow.com/questions/14525982/getting-request-payload-from-post-request-in-java-servlet">this</a> article as well as <a href="https://stackoverflow.com/questions/3831680/httpservletrequest-get-post-data">this</a> one), and none of them seem to be helping me. Both seem to suggest using a <code>request.getReader()</code> method, but that isn't what I need. I need a way to directly access the form variables and their respective values.</p>
  
  <p>I can't tell if my client code is incorrectly formatting the POST request and sending the form data in a way that the Java servlet can't handle, or if the Java servlet isn't coded correctly to handle the request.</p>
  
  <p>When I run Firebug and submit the form, here are the contents of the <code>Post</code> tab associated with the request:</p>
  
  <pre><code>-----------------------------18671963685702-some-really-long-number
  Content-Disposition: form-data; name="email"
  
  testing@example.com
  -----------------------------18671963685702-another-really-long-number
  Content-Disposition: form-data; name="password"
  
  12345
  -----------------------------18671963685702-and-another-really-long-number--
  </code></pre>
  
  <p>To an untrained eye this <em>looks</em> like the client is correctly sending a non-NULL <code>email</code> variable, as well as a non-NULL <code>password</code> variable, but again, I'm in unfamiliar territory here...</p>
  
  <h2>The bottom line</h2>
  
  <p>I need to first figure out whether this is a client- or server-side bug. This question is an attempt to either diagnose it as a server-side bug, or rule it out as such. So do any battle-weary servlet veterans see anything wrong the either the HTTP request, or the servlet code handling it? And if this is a server bug, what do I need to change to access my form variables?</p>