标签:
关键点:
datagrid:
{"total":1,"rows":[{"name":"小李"}]}
combobox:
[{"value":"001","text":"小李"},{"value":"002","text":"小红"}]
其他:
public String getJsonData(){ Map<String,Object> data = new HashMap<String,Object>(); List<Map<String,Object>> personList = new ArrayList<Map<String,Object>>(); Map<String,Object> person = new HashMap<String,Object>(); person.put("name", "小李"); personList.add(person); data.put("total", personList.size()); data.put("rows", personList); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out; try { out = response.getWriter(); out.println(JSONObject.fromObject(data)); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return null; }
片段一
InputStream inputStream; public InputStream getInputStream() { return inputStream; } public void setInputStream(InputStream inputStream) { this.inputStream = inputStream; } public String getJsonData(){ Map<String,Object> data = new HashMap<String,Object>(); List<Map<String,Object>> personList = new ArrayList<Map<String,Object>>(); Map<String,Object> person = new HashMap<String,Object>(); person.put("name", "小李"); personList.add(person); data.put("total", personList.size()); data.put("rows", personList); inputStream = new ByteArrayInputStream(JSONObject.fromObject(data).toString().getBytes()); return "inputStream"; }
片段二
<result type="stream" name="inputStream"> <param name="bufferSize">1024*1024</param> <param name="inputName">inputStream</param> </result>
片段一
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> <version>2.3.15.3</version> </dependency>
片段二
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="pages" namespace="/pages" extends="struts-default,json-default"> <global-results> <result name="json" type="json" > <param name="root">jsonObject</param> </result> </global-results> </package> </struts>
片段三
// 返回 JSON Object jsonObject; // 页面跳转 static final String JSON = "json"; public Object getJsonObject() { return jsonObject; } public void setJsonObject(Object jsonObject) { this.jsonObject = jsonObject; }
本实现方式需要引入struts2-json-plugin
见smse
标签:
原文地址:http://www.cnblogs.com/zno2/p/4521457.html