jsp页面:
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
<h1>数据展示</h1>
<h2>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<s:iterator value ="#session.tZhengtiDataList" var="mycontent" status="indexValue">
<tr>
<td><s:property value="#mycontent.statisticTime" /></td>
<td><s:property value="#mycontent.area"/></td>
<td><s:property value="#mycontent.insurBody"/></td>
<td><s:property value="#mycontent.preminum"/></td>
</tr>
</s:iterator>
</table>
</h2>
</body>
</html>
action页面:
package com.market.action;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import com.market.domain.IZhengtiData;
import com.market.serivce.ZhengtiDataService;
import com.opensymphony.xwork2.ActionContext;
public class AdminHomeAction{
public List<IZhengtiData> tZhengtiDataList;
ZhengtiDataService zhengtiDataService = new ZhengtiDataService();
private Map<String, Object> result = new HashMap<String, Object>(); // result变量用于传送Json变量的返回值
public String selectCurrentData(){
ActionContext ctx = ActionContext.getContext();
List<IZhengtiData> tZhengtiDataList = null;
tZhengtiDataList = zhengtiDataService.selecTZhengtiDatas();
ctx.getSession().put("tZhengtiDataList",tZhengtiDataList);
JSONArray jsonArray = JSONArray.fromObject(tZhengtiDataList);
ctx.getSession().put("jsonArray",jsonArray);
System.out.println("执行json数据打印方法和selectCurrentData……");
System.out.println(jsonArray);
result.put("total", tZhengtiDataList.size());
result.put("rows", tZhengtiDataList);
//this.printZhengtiDataList(tZhengtiDataList);
return "plist";
}
private static void printZhengtiDataList(final List<IZhengtiData> tZhengtiDataList)
{
int count = 0;
for (IZhengtiData zhentTZhengtiData : tZhengtiDataList)
{
System.out.println(MessageFormat.format("============= zhentTZhengtiData[{0}]=================", ++count));
System.out.println("统计地区: " + zhentTZhengtiData.getStatisticTime());
System.out.println("保险主体: " + zhentTZhengtiData.getArea());
System.out.println("统计时间: " + zhentTZhengtiData.getInsurBody());
System.out.println("保费数据: " + zhentTZhengtiData.getPreminum());
}
}
public List<IZhengtiData> gettZhengtiDataList() {
return tZhengtiDataList;
}
public void settZhengtiDataList(List<IZhengtiData> tZhengtiDataList) {
this.tZhengtiDataList = tZhengtiDataList;
}
public ZhengtiDataService getZhengtiDataService() {
return zhengtiDataService;
}
public void setZhengtiDataService(ZhengtiDataService zhengtiDataService) {
this.zhengtiDataService = zhengtiDataService;
}
public Map<String, Object> getResult() {
return result;
}
public void setResult(Map<String, Object> result) {
this.result = result;
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" namespace="" extends="struts-default">
<action name="Welcome_*" class="com.market.action.UserLoginAction" method="{1}">
<result name="main">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
<package name="jobModel" namespace="/" extends="json-default">
<action name="AdminHomeAction_*" class="com.market.action.AdminHomeAction" method="{1}">
<result type="json" name="plist">
<param name="root">result</param>
</result>
</action>
</package>
</struts>