如何发送Json到Struts2? [英] How to send Json to Struts2?
本文介绍了如何发送Json到Struts2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个Json对象,我不知道如何在struts2中获取它,其中有两个数组,如何在Java中将其传输到ArrayList?
There is a Json object and I don't know how to get it in struts2,there are two arrays in it,how to transfer it to ArrayList in java?
var params = {
'goodsIdList':goodsIdList,
'goodsCountList':goodsCountList
}
console.log(params);
$.ajax({
type: 'post',
url: "checkGoodsIsEnough",
data: params,
dataType:"json",
async: true,
success: alert("success"),
error: function (jqXHR) {
alert(jqXHR.status);
}
})
推荐答案
我将假定您已经将此配置添加到struts.xml中以提供JSON格式支持:
I will suppose that you have already added this config to your struts.xml to provide JSON format support :
<action name="checkGoodsIsEnough" class="ClassOf_CheckGoodsIsEnough">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="json">
<param name="enableSMD">true</param>
</interceptor-ref>
</action>
在这种情况下,请不要忘记通过使用以下命令将您的JavaScript对象转换为JSON字符串格式:
If this is the case, dont forget to convert your javascript object to JSON string format by using :
var JsonParams = JSON.stringify(params);
然后尝试执行Post调用,如下所示:
And then try to do the Post call as follow :
$.ajax({
type: 'post',
url: "checkGoodsIsEnough",
data: JsonParams,
dataType:"json",
async: true,
success: alert("success"),
error: function (jqXHR) {
alert(jqXHR.status);
}
});
希望获得帮助!
这篇关于如何发送Json到Struts2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文