<s:iterator value="resultType" id="geneUi">   //拿到要遍历的Map对象
<s:iterator value="#geneUi.value" id="typeMap"> //取得Map对象里代表value值的嵌套Map对象
<tr>
<s:iterator value="#typeMap.value" id="typeB"> //取得嵌套的Map对象中代表value值的List对象
<td><s:property value="#typeMap.key"/></td> //取得嵌套Map对象中遍历的每个元素的key值
<td><s:property value="#typeMap.value.size"/></td> //取得List对象的大小
<td><s:property value="typeB"/></td> //取得List对象的每个元素值
</s:iterator>
</tr>
</s:iterator>
</s:iterator> 其中第一个iterator的value值resultType为下面action中的成员变量 public class ***Action extends SupportAction {
private Map<String, Map<String, List<String>>> resultType = new HashMap<String, Map<String,List<String>>>(); ..........
.........
}

  

package com.zx.demo.action;  

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.model.Student; public class MapAction extends ActionSupport
{ private Map<String,String> map; private Map<String,Student> studentMap; private Map<String,String[]> arrayMap; private Map<String,List<Student>> listMap; public String testMap()
{
map=new HashMap<String,String>();
map.put("1", "one");
map.put("2", "two"); studentMap=new HashMap<String,Student>();
studentMap.put("student1",new Student(new Long(1),"20034140201","张三1","男",25));
studentMap.put("student2",new Student(new Long(2),"20034140202","张三2","女",26));
studentMap.put("student3",new Student(new Long(3),"20034140202","张三3","男",27)); arrayMap=new HashMap<String,String[]>();
arrayMap.put("arr1", new String[]{"1","2003401","leejie","male","20"});
arrayMap.put("arr2", new String[]{"2","2003402","huanglie","male","25"});
arrayMap.put("arr3", new String[]{"3","2003403","lixiaoning","male","21"}); listMap=new HashMap<String,List<Student>>(); List<Student> list1=new ArrayList<Student>();
list1.add(new Student(new Long(1),"20034140201","张三1","男",25));
list1.add(new Student(new Long(2),"20034140202","张三2","男",25));
list1.add(new Student(new Long(3),"20034140203","张三3","男",25));
listMap.put("class1", list1); List<Student> list2=new ArrayList<Student>();
list2.add(new Student(new Long(1),"20034140301","李四1","男",20));
list2.add(new Student(new Long(2),"20034140302","李四2","男",21));
list2.add(new Student(new Long(3),"20034140303","李四3","男",22));
list2.add(new Student(new Long(4),"20034140304","李四4","男",23));
listMap.put("class2", list2); return SUCCESS; } public Map<String, String> getMap() {
return map;
} public void setMap(Map<String, String> map) {
this.map = map;
} public Map<String, Student> getStudentMap() {
return studentMap;
} public void setStudentMap(Map<String, Student> studentMap) {
this.studentMap = studentMap;
} public Map<String, String[]> getArrayMap() {
return arrayMap;
} public void setArrayMap(Map<String, String[]> arrayMap) {
this.arrayMap = arrayMap;
} public Map<String, List<Student>> getListMap() {
return listMap;
} public void setListMap(Map<String, List<Student>> listMap) {
this.listMap = listMap;
} }

  

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>struts2中的map遍历总结</title>
</head>
<body>
<b>1.map中的value为String字符串</b><br>
<s:iterator value="map" id="column">
<s:property value="#column"/><br>
key: <s:property value="key"/><br>
value:<s:property value="value"/><br>
******************************************<br>
</s:iterator> <b>2.map中的value为Student对象</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>key=value</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr>
<s:iterator value="studentMap" id="column">
<tr>
<td><s:property value="#column"/></td>
<td><s:property value="value.id"/></td>
<td><s:property value="value.num"/></td>
<td><s:property value="value.name"/></td>
<td><s:property value="value.sex"/></td>
<td><s:property value="value.age"/></td>
</tr>
</s:iterator>
</table>
<p> <b>3.map中的value为String数组</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>key=value</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr>
<s:iterator value="arrayMap" id="column">
<tr>
<td><s:property value="#column"/></td>
<td><s:property value="value[0]"/></td>
<td><s:property value="value[1]"/></td>
<td><s:property value="value[2]"/></td>
<td><s:property value="value[3]"/></td>
<td><s:property value="value[4]"/></td>
</tr>
</s:iterator>
</table>
<p>
<b>4.map中的value为list集合</b>
<table border="1" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td>class</td>
<td>ID</td>
<td>num</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr> <s:iterator value="listMap" id="column">
<s:set name="total" value="#column.value.size"/>
<s:iterator value="#column.value" status="s">
<tr>
<s:if test="#s.first"><td rowspan="${total}"><s:property value="#column.key"/></td></s:if>
<td><s:property value="id"/></td>
<td><s:property value="num"/></td>
<td><s:property value="name"/></td>
<td><s:property value="sex"/></td>
<td><s:property value="age"/></td>
</tr>
</s:iterator>
</s:iterator>
</table> </body>
</html>

  

Struts标签<s:iterator>遍历访问复杂Map对象的更多相关文章

  1. Struts 2的iterator标签来遍历一个含有双层List的嵌套

    今天碰到一个很有意思的问题,就是需要用Struts 2的iterator标签来遍历一个含有双层List的嵌套. 首先我们从最基础的说起,用iterator标签遍历一个List. 如果Action中有一 ...

  2. Play Framework常用标签list,set,如何遍历list、map类型数据

    最近一段时间的项目都是在Play这个框架上进行开发的,挺强大的,但不足之处也挺多的.今天分享下play中强大的标签,遍历list,map类型的数据的用法. 遍历单纯的list数据,例如:List< ...

  3. Java SE之For增强与Iterator遍历器提取数据(附Map.Entry)

    增强for循环: 1.操作数组 2.操作List集合 3.操作Map集合    1.map.values()法    2.map.keySet()法  [传统方法]    3.Map.Entry法   ...

  4. struts 标签库注解

    在struts2中有着一套像html一样的标签,俗称struts2标签,大多数公司使用ssh都是使用html标签,但为了保持项目的统一性,有的公司还是使用的struts2的标签,下面是一些常用的str ...

  5. Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用

    我之前虽然会用,但是一直分不清彼此之间有什么区别,所以查找资料,将它们进行整合区分,加深了解, 一 介绍 1.Struts2的作用   Struts2标签库提供了主题.模板支持,极大地简化了视图页面的 ...

  6. JSTL、EL、ONGL、Struts标签的区别与使用

     一.JSTL 来源 我们使用JSP开发信息展现非常方便,也可嵌入java代码用来实现相关逻辑,但同样带来了很多问题: jsp维护难度增加 出事提示不明确,不容易提示 分工不明确等 解决上面的问题可以 ...

  7. Struts标签库详解【3】

    struts2标签库详解 要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部加入以下的代码: <%@taglib prefix="s" uri= ...

  8. Struts标签库详解【1】

    struts2标签详解 要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部加入以下的代码: <%@taglib prefix="s" uri=& ...

  9. ongl与Struts标签

    一.ONGL OGNL 的全称是“Object-Graph Navigation Language”,即对象图导航语言,它是一种功能强大的开源表达式语言.使用这种表达式语言可以通过某种表达式语法存取  ...

随机推荐

  1. #Leet Code# Best Time to Buy and Sell Stock

    描述:数组 A,对于 i < j, 找到最大的 A[j] - A[i] 代码: class Solution: # @param prices, a list of integer # @ret ...

  2. IT从业人员必看的十几个论坛

    IT方面的论坛太多了,有综合,有专业,有行业,在各个论坛里混了几年,体会颇深,以前是论坛哪里人多,往哪里去,新浪论坛,网易是经常去的,人多啊,好几十万,去了以后才发现没有意思,没有共同的语言,于是逛专 ...

  3. POJ 3264 Balanced Lineup 简单RMQ

    题目:http://poj.org/problem?id=3264 给定一段区间,求其中最大值与最小值的差. #include <stdio.h> #include <algorit ...

  4. IOS公司开发者账号申请详细教程--1 备用

    谈到苹果开发者账号,我们需要区分一下个人账号.公司账号和企业账号这三种,还有一种是教育账号,这个就不多说了. 个人账号:个人申请用于开发苹果app所使用的账号,仅限于个人使用,申请比较容易,$99. ...

  5. Hbase热点问题

    需求描述:扫描(查询)某个区间--->列用hbase多节点的资源,分布式扫描,加快速度==> 然后拼接到一起 如何打散数据 冠字号逆序,hash 并不一定数据连续就会造成热点,这个是由数据 ...

  6. python之--条件判断和循环

    Python之判断 和其他语言一样,python同样具有条件判断和循环的操作,比如我们可以编写一个简单的判断操作:使用if关键字可以达到判断的效果,如下例: >>> test_if ...

  7. 关于Json传递的日期/Date(数字)/解析

    在将DateTime类型的数据Json后传到前台展示,出现如下效果 ,在客户端如何解析呢?在jquery easyui 的字段中加一个格式化的函数调用.   { field: 'CreateTime' ...

  8. 转:三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)

    http://blog.csdn.net/liujun13579/article/details/7772491 网格布局特点: l  使容器中的各组件呈M行×N列的网格状分布. l  网格每列宽度相 ...

  9. bzoj2434

    利用了bzoj3172提到的性质,x串在y串中的出现的次数即为在fail树上以x结尾节点为根的子树中有多少个节点在y串上所以很明显我们要离线解决,我们先把询问按y分类存起来然后我们顺着操作顺序来,出现 ...

  10. ArcGIS_系列中文教程

    转自:http://www.cnblogs.com/gispeng/archive/2008/04/15/1154212.html  ArcGIS_系列中文教程 如链接有问题请在留言中说明ArcGIS ...