I am using Ajax and JSON to pass some array to my servlet. I am using Struts1.3 as my framework. I am receiving null as the parameter when i get the parameter in ActionServlet.
$.ajax({
url: "startTest.do?cmdField=ajax",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:JSON.stringify(answerJson),
contentType:"application/json"
//complete:callback
});
my JSON object answerJson value :
{"answer":[{"qId":"13","selAns":"A"},{"qId":"2","selAns":"A"},{"qId":"12","selAns":"A"},{"qId":"6","selAns":"A"}]}
In my servlet, if I use the below statement gives null.
System.out.println(request.getParameter("answer"));
I use tried to use GSON as
JsonAns ans = gson.fromJson(request.getParameter("answer"), JsonAns.class);
which in turn gave me error.
How can i get the parameter values into List using GSON?