So I am using this method to send my form data to a servlet:
function send() {
var formData = $("#myForm").serialize();
$.ajax({
url: "generateutil",
async: true,
data: {
formData: formData
},
dataType: 'text',
success: function(data) {
//do the do
}
});
}
Using a form like this:
<form id="myForm" method="POST">
<input type="text" name="firstName" id="firstName"/>
</form>
My question is, how do I then GET this information from the servlet? Trying the regular request.getParameter("firstName") always yields null values. I suppose I have to do something with the formData first or something but I cannot find ANYTHING about this anywhere online, tons of information on how to pass the data, but none on how to actually retrieve it.
I suspect I am missing something very obvious or doing something wrong...
P.S: I can't simply submit the form normally for reasons I don't really want to get into here.
EDIT: I know the data is indeed sent to the server as I can see the whole thing in fire bug:
formData
firstName=MyName&lastName=MyLastName.....
Servlet code:
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String toPrint = "";
toPrint += "First name: ";
toPrint += request.getParameter("firstName");
out.write(toPrint);
}
That's the gist of it anyway, there are dozens of other variables that I add up but it's more of the same and it'd take pages to fit the entire thing here. The problem is that request.getParameter("firstName"); returns null, as do all the other variables, even though I see them having an actual value in the parameter tab of firebug.