【发布时间】:2013-10-11 02:02:03
【问题描述】:
我想在 jquery 中使用 ajax 将 json 数据从 jsp 页面传输到操作类。 以下是jquery代码。
$.ajax({
type : 'POST',
url : contextPath+"/postData.action",
async: false ,
data :json,
dataType:"json",
contentType: 'application/json; charset=utf-8',
contentType: "application/json",
success : function(result) {
}
});
下面是动作类代码:
private String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public String execute()
{
System.out.println(data);
return ActionSupport.SUCCESS;
}
Struts.xml 配置文件
<action name="postData" class="demo.StoreJSONData" >
<result name="success">/jsp/output.jsp</result>
</action>
示例json代码代码:
{
"rectangle": {
"0": {
"id": "rectangle_1",
"displayData": "<div class=\"\" style=\"background: none repeat scroll 0% 0% rgb(255, 255, 255); width: 389px; height: 129px; position: absolute; left: 92px; top: 360px; border: 1px solid black; z-index: 4;\" id=\"rectangle_1\"></div>"
}
},
"eclipse": {
"0": {
"id": "eclipse_1",
"displayData": "<div class=\"\" style=\"position: absolute; z-index: 5; background-color: rgb(243, 239, 15); border: 1px solid black; width: 245px; height: 83px; border-radius: 50% 50% 50% 50%; left: 563px; top: 445px;\" id=\"eclipse_1\"></div>"
}
}
}
【问题讨论】:
-
请贴一些你试过的代码!!
-
我已将代码添加到问题中。