我正在使用ajax将数据传递到servlet。据我所知,标准方法通常是这样的:
$.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));
}
});
然后在jsp页面中,将这样检索数据:
String id = request.getParameter("id");
String name = request.getParameter("name");
毫无疑问,这将起作用。现在,如果我想将数据存储为对象怎么办。在我的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));
}
});
然后,我使用相同的方式:
String recipient = request.getParameter("recipient");
这将返回空值。如何准确地从对象中检索所需的数据值?
喵喔喔
噜噜哒
相关分类