title: How to use the information in XMLHttpRequest.send(string)
body: <p>I'm sending a POST request with a string in the <code>.send()</code> part which is <code>"id=jeff&amp;command=test"</code>.</p>
  
  <p>How do I parse and use these values in Java via the <code>HttpServletRequest</code> object?</p>
  
  <p>I've tried changing the content type to <code>text/html</code> and <code>application/x-www-form-urlencoded</code>.
  My java server is embedded jetty btw.</p>
  
  <pre><code>var text = form.command.value;
  var xmlhttp = new XMLHttpRequest();
  
      xmlhttp.onreadystatechange=function()
      {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
            {
              xmlhttp.responseText
            }
          }
  
      xmlhttp.open("POST", 'go', true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.send("id=jeff&amp;command=" + text);
  </code></pre>
  
  <p>here's my Java code</p>
  
  <pre><code>public class GoHandler extends HttpServlet 
  {
  Commands c = Commands.getInstance();
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {
      BufferedReader reader = request.getReader();
      String str = "";
      while ((str = reader.readLine()) != null)
      {
          System.out.println(str);
      }
  
      String p = request.getParameter("id");
      String input = request.getParameter("command"); 
      System.out.print(p);
  </code></pre>
  
  <p>here is my output when I make the request from a browser</p>
  
  <p>id=jeff&amp;command=test (this is from the buffered reader)</p>
  
  <p>null (this is from my String p which should be the id)</p>
  
  <p>here's Chrome's toolkit thing..</p>
  
  <pre><code>Request URL:http://localhost:8080/go
  Request Method:POST
  Status Code:200 OK
  Request Headersview source
  Accept:*/*
  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8
  Connection:keep-alive
  Content-Length:20
  Content-Type:application/xml
  Host:localhost:8080
  Origin:http://localhost:8080
  Referer:http://localhost:8080/
  User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko)     Chrome/22.0.1229.79 Safari/537.4
  Request Payload
  id=jeff&amp;command=test
  Response Headersview source
  Content-Length:66
  Content-Type:application/json;charset=utf-8
  Server:Jetty(8.1.7.v20120910)
  </code></pre>
  
  <p>my response from the server</p>
  
  <pre><code>{"flavor":"You are in the goHandler"}
  </code></pre>