struts2中的jsp页面通过iterator调取后台action中的list集合

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>    


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值