Struts2返回XML,JSON格式
2.Action里面的方法import net.sf.json.JSONArray;import net.sf.json.JSONObject;........./** * 通过bean生成JSON数据 * @param bean bean对象 * @return 生成的JSON数据*/public static String getJsonFromBean(Object bean){ try{ JSONObject JsonObject = JSONObject.fromObject(bean); return JsonObject.toString(); }catch(Exception e){ e.printStackTrace(); } return null;}