struts2中的jsp页面通过iterator调取后台action中的list集合
2017-02-01 01:00
525 查看
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>
<%@ 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>
相关文章推荐
- 请求Action的路径、参数设置及Struts2的Action向JSP传输List集合并且将数据显示在页面上
- Struts2的Action向JSP传输List集合并且将数据显示在页面上
- Struts2的Action向JSP传输List集合并且将数据显示在页面上
- struts2项目jsp页面通过js调取action中的封装的json
- action传list到jsp页面,js接收并解析list(struts2中)
- Action返回自定义类的List集合通过JSP中的Struct2标签显示
- jsp页面获取后台传过来的list集合的长度
- struts2,jsp页面向action提交list对象
- jsp页面,使用Struts2标签,传递和获取Action类里的参数,注意事项。<s:a action><s:iterator><s:param>ognl表达式 在编写SSH2项目的时候,除
- Struts2——将字符串、对象、list集合保存到值栈中,在jsp页面中获取的方法
- Struts2 前端JSP页面获取后台Action属性值的几种方法
- struts2 jsp页面向action提交list对象
- 一段可以使用的 hibernate获得对象->action存入List->jsp页面用<s:iterator>迭代的代码
- struts2后台Action接收jsp页面的值
- struts2的s:iterator标签在jsp页面获取action中数组对象
- jsp 页面中用struts2 标签遍历集合(list map)
- 在action中将字符串、对象、list集合保存到值栈中,在jsp页面中获取的方法
- Jsp页面如何集合List传递到后台控制端
- JSP页面结合Struts2如何传递复选框对应的id数组到后台action中
- jsp页面通过 request对象直接获取 struts2 Action的变量的值。