I am trying to call a servlet from jQuery's .ajax() function.
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?
This is my html:
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1>
<script type=text/javascript src=jquery.js></script>
<script type=text/javascript>
function login(){
$(#loading).hide();
var email = document.nameForm.email.value;
$.ajax({
type: GET,
url: ProcessForm,
data: email=+email,
success: function(result){
alert(result);
}
});
}
</script>
<title>My AJAX</title>
</head>
<body>
<p>This time it's gonna work</p>
<form name=nameForm id=nameForm method=post action=javascript:login()>
Email
loading
</body>
</html>
And my web.xml
<?xml version=1.0 encoding=UTF-8?>
<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>
<display-name>ajaxtry</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ProcessForm</servlet-name>
<servlet-class>com.ajaxtry.web.ProcesFormServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProcessForm</servlet-name>
<url-pattern>/ProcessForm</url-pattern>
</servlet-mapping>
</web-app>
The servlet is just a template at the moment:
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));
}
}