日期:2014-05-16  浏览次数:20319 次

json-lib的使用
1.action处理js的request数据
Object postData = ServletActionContext.getRequest().getParameter("postData");
JSONArray jsonArray = JSONArray.fromObject(postData);
此处的postData是ajax请求的一个js数组

2.action发送response数据到js
SchoolCourse sc = new SchoolCourse();
JSONObject jsonObj = JSONObject.fromObjct(sc);

@JSON
public JSONObject getJsonObj() {
  return jsonObj;
}

struts.xml
<action..>
  <result type="json" >
    <param name="includeProperties">
       jsonObj
    </param>
  </result>
</action>