Jquery 我正在发送json数据并尝试进入struts2操作类
我的json数据是 {postData:[{itemId:mcw750,currentQty:90,saleQty:8,单价:100,salePrice:800}]}Jquery 我正在发送json数据并尝试进入struts2操作类,jquery,struts2,Jquery,Struts2,我的json数据是 {postData:[{itemId:mcw750,currentQty:90,saleQty:8,单价:100,salePrice:800}]} var postData = JSON.stringify(data); alert("The following data are sending to the server:\n"+postData);\\here i m getting all values.. $.ajax({ type: "POST",
var postData = JSON.stringify(data);
alert("The following data are sending to the server:\n"+postData);\\here i m getting all values..
$.ajax({
type: "POST",
url: "http://localhost:7001/Final_Subgrid2/jsonaction.action",
dataType:"JSON",
data:postData,
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(response, textStatus, xhr) {
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error");
}
});
在Action类中,我有一个带有setter和getter的公共列表postData。
请告诉我为什么在action类中获取空数据
我有Employee pojo类。itemId、currentQty、saleQty、unitPrice、totalPrice
当我将更新后的jqgrid数据发送到action类时,它将获得空值。。
我的json数据没有问题,ajax正在向ActionBug发送正确的数据,如firebug所示
我的动作映射是。
我仍然得到空值,请指导我正确的方向
最后我终于解决了我的问题..感谢大家的帮助..postdata不需要getter/setter,postdata项将作为请求参数单独发送,因此itemId作为itemId在requestmap中。 Postdata未作为json发送 在操作类中为postdata中发送的所有项目添加getter/setter
[get/set]ItemId[get/set]CurrentQty,….我已经修改了struts.xml及其作品
<action name="jsonaction" class="main.com.java.action.GetData" method="getJson">
<interceptor-ref name="json">
<param name="contentType">application/JSON</param>
<param name="excludeNullProperties">true</param>
</interceptor-ref>
<result name="success" type="json"/>
</action>
可能是因为你没有使用JSON插件,但谁知道呢;你不会说。我正在使用struts2-json-plugin-2.3.4.jar。我已经检查了它是否正常工作,但仍然没有在action类中获取数据。请告诉我。我也检查了firebug。我的ajax发送了正确的数据,但我的action类响应为空。然后你需要提供更多信息。最简单的方法是在github上托管。我已经为所有项目添加了get/set,但我在actions类中仍然得到null值。请指导我…我应该在action类中反序列化json数据吗。我在internet上看到我们必须在action类中反序列化json数据。我很困惑。我正在获取eclipse控制台输出,如执行操作方法=getJson Json DataRetrieve Data==nullJson DataRetrieve Data==null00:30:13086调试JSONUtil:68-[Json]{currentQty:null,itemId:null,Json:success,salePrice:null,saleQty:null,sentData:{},unitPrice:null}我已经修改了我的struts.xml及其作品。。application/JSON-true