I am using ajax to pass data to servlet. From what I know the standard way usually goes like this:
$.ajax({
url: 'page.jsp',
type: 'POST',
data: {
id:value,
name:value2
},
success: function (data) {
alert("Successfully initiated email to queue");
},
error: function (request, error) {
alert("Request: " + JSON.stringify(error));
}
});
And in the jsp page, one would retrieve the data like this:
String id = request.getParameter("id");
String name = request.getParameter("name");
This would work no doubt. Now what if I want to store the data as objects. Like this in my JavaScript:
var data;
if(condition){
data={
'recipient': recipient,
'subject': subject,
'content': content,
'id':"<%=id%>",
'hash':"<%=hash%>",
'multiemail':"no"
}
}else{
data= {
'recipient': recipient,
'subject': subject,
'content': content,
'arrayList':<%=array%>,
'multiemail':"yes"
}
}
$.ajax({
url: 'page.jsp',
type: 'POST',
data: {
info:data
},
success: function (data) {
alert("Successfully initiated email to queue");
},
error: function (request, error) {
alert("Request: " + JSON.stringify(error));
}
});
Then, I used the same way:
String recipient = request.getParameter("recipient");
And this would returns null value. How do I exactly retrieve the data value I want from the object?