title: Unable to send variable value from JS to Java Class
body: <p>I am using Google Sign-in to and get the user email and token-id. I am capturing the values in the JavaScript function and this works correctly. Here's the code snippet used. I have a http servlet class that needs this data.</p>
  
  <pre><code>&lt;div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark" onSubmit=&gt;&lt;/div&gt;
  &lt;script&gt;
  function onSignIn(googleUser) { 
  
      // The ID token you need to pass to your backend:
      var id_token = googleUser.getAuthResponse().id_token;
      console.log("ID Token: " + id_token); 
  
      //send to backend
      postIt(id_token);
    };
  
  
    function postIt(id_token) { 
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
              if (this.readyState == 4 &amp;&amp; this.status == 200) {
                document.getElementById("demo").innerHTML = this.responseText;
              }
            } 
            xhttp.open("POST","index.jsp", true );
            xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhttp.send("id_token");   
    }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>My Servlet looks like this:</p>
  
  <pre><code>   public class TestServlet extends HttpServlet {
  
     protected void doPost(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
  
      String id_token;
      String email; 
  
      id_token=request.getParameter("id_token"); 
  
      HttpSession session=request.getSession(true);
      System.out.println("all is ok");
      try {
              System.out.print(id_token); 
  
          } catch (Exception e) {
  
              e.printStackTrace();
          }
      }
  }  
  </code></pre>
  
  <p>I get uncaught TypeError in the browser console. I think the problem is in the postIt  function.
  I am not able to understand how do I send the id_token value to the servlet. Can someone please correct my code? </p>