请问struts2 如何获得 qjuery ajax 传输的json 对象
需要用到哪些jar包
struts.xml 中如何写?
action中如何接收 json的对象?
可否给个具体案例? 我按照网上的写的都不能运行。
------解决思路----------------------
后台
private JSONObject json;
public void setJson(JSONObject json) {
this.json = json;
}
public JSONObject getJson() {
return json;
}
前台http://127.0.0.1:8080/test?json={"id":1,"name":vs}
------解决思路----------------------
$.ajax({
url : "${contextPath}/web/toEditGeneAddress.html",
type : "POST",
dataType : "json",//必须加这个
data : {
'geneAddress.geneAddressId' : geneAddressId
},
success : function(data) {
}
});
其中geneAddress对应你action里面的对象,geneAddressId对应这个对象里面的属性
------解决思路----------------------
private GeneAddress geneAddress;需要在action层定义,并生成这个对象的get和set方法,如果你只是想接收geneAddressId,那就这样写$.ajax({
url : "${contextPath}/web/toEditGeneAddress.html",
type : "POST",
dataType : "json",//必须加这个
data : {
geneAddressId: geneAddressId
},
success : function(data) {
}
});
其中需要在action层定义geneAddressId,并且生成geneAddressId的get和set方法