struts2发送json语句

来源:互联网 发布:卖家怎么加入农村淘宝 编辑:程序博客网 时间:2024/06/03 18:33

1.首先加入struts2的json包

struts2-json-plugin.jar

json-lib-2.3.jdk.jar


2.action(如果有接收到的json串,要自己解析)

String resultJson;execute(){   JSONObject job = new JSONObejct();   Map<String,String> msg = new HashMap<String,String>();   msg.put();......   job = JSONObject.fromObject(msg);//转化为json对象   resultJson = job.toString();//转化为json串   return "json";}

3.struts2

注意继承json-default

  <package name="users" extends="json-default" namespace="/">    <global-results>    <result name="input">/index.jsp</result>    </global-results>        <action name="comboAction" class="com.fox.extjs.action.ComboData">    <result name="json" type="json">    <param name="root">resultJson</param>    </result>    </action>        </package>








原创粉丝点击