title: How to call a servlet from a jQuery's $.ajax() function
body: <p>I am trying to call a servlet from jQuery's .ajax() function.</p>
  
  <p>At the moment I don't think I am even calling the servlet or passing paramaters to it, however lots of Googling doesn't seem to have helped. Any ideas?</p>
  
  <p>This is my html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  function login(){  
  
    $("#loading").hide();
  
    var email = document.nameForm.email.value;  
    $.ajax({  
      type: "GET",  
      url: "ProcessForm",  
      data: "email="+email,  
      success: function(result){  
        alert(result);
      }                
    });  
  }        
  &lt;/script&gt;
  &lt;title&gt;My AJAX&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;This time it's gonna work&lt;/p&gt;
  &lt;form name="nameForm" id="nameForm" method="post" action="javascript:login()"&gt;
  </code></pre>
  
  <p>Email 
   
      
       
      loading</p>
  
  <pre><code>&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;ajaxtry&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
  &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;servlet&gt;
  &lt;servlet-name&gt;ProcessForm&lt;/servlet-name&gt;
  &lt;servlet-class&gt;com.ajaxtry.web.ProcesFormServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;ProcessForm&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/ProcessForm&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The servlet is just a template at the moment:</p>
  
  <pre><code>package com.ajaxtry.web;
  
  // imports here
  
  public class ProcessFormServlet {
  
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
  
      System.out.println(request.getParameter("email")); 
    }
  }
  </code></pre>