1.MapAction.java

import java.util.ArrayList;   
import java.util.HashMap;   
import java.util.List;   
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport 
import com.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;   
    }   
       
       
}

2.testMap.jsp 
<%@ 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>   
     
   <1.<s:iterator value="listHashMap" id="listid">   
   <s:iterator value="#listid.value" id="listidsub">   
       <tr>   
            <td><s:property value="key"/></td>   
            <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>

 

struts2 <s:iterator> 遍历方法的更多相关文章

  1. 疑问:Iterator 遍历器和数据集合各种遍历方法的区别

    https://es6.ruanyifeng.com/#docs/iterator Iterator(遍历器)的概念 Iterator 接口主要供for...of消费 Iterator 的遍历过程是: ...

  2. 转:Struts2<s:iterator value="" var="lst">中var的使用和一些标签的使用体会

    比如<s:iterator value="pmOperateList" var="lst"> <!-- iterator加上var 等价于重新 ...

  3. struts2 <s:iterator> status属性

    struts2 <s:iterator> status属性 转载▼   iterator标签主要是用于迭代输出集合元素,如list set map 数组等,在使用标签的时候有三个属性值得我 ...

  4. [转]使用Enumeration和Iterator遍历集合类

    原文地址:http://www.cnblogs.com/xwdreamer/archive/2012/05/30/2526268.html 前言 在数据库连接池分析的代码实例中,看到其中使用Enume ...

  5. javase-常用三种遍历方法

    javase-常用三种遍历方法 import java.util.ArrayList; import java.util.Iterator; import java.util.List; public ...

  6. Java中Map的三种遍历方法

    Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历.   告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...

  7. Map的五种遍历方法

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  8. 集合类List,set,Map 的遍历方法,用法和区别

    遍历list: 方法一: for(String s:lists){ System.out.println(s); } 方法二: System.out.println("list with i ...

  9. java list三种遍历方法性能比較

    从c/c++语言转向java开发,学习java语言list遍历的三种方法,顺便測试各种遍历方法的性能,測试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象 ...

随机推荐

  1. 调用[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad判断设备

    将模拟器改为Ipad时,调用[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad判断设备是否为Ipad,但程序并 ...

  2. java反射机制初探

    最近和一位师兄交流了一下Java,真可谓是大有收获,让我好好的学习了一下javad的反射机制,同终于明白了spring等框架的一个基本实现的思想,那么今天就和大家分享一下java的反射机制. 反射,r ...

  3. UVa1592 数据库(摘)

    输入一个n行m列的数据库(1<=n<=10000,1<=m<=10),是否存在两个不同行r1,r2和两个不同列c1,c2,使得这两行和这两行相同(即(r1,c1)和(r2,c1 ...

  4. eclipse中配置免安装tomcat7

    参看如下链接:http://hi.baidu.com/gpy11/item/744c13e14614c9b52e140b25

  5. JDBC学习入门

    一.JDBC相关概念介绍 1.1.数据库驱动 这里的驱动的概念和平时听到的那种驱动的概念是一样的,比如平时购买的声卡,网卡直接插到计算机上面是不能用的,必须要安装相应的驱动程序之后才能够使用声卡和网卡 ...

  6. C# ?? 运算符,不能忘记的知识点

    最近项目中有一个bug被测试(是黑盒测试)发现了,跟了老半天代码,才找到这个问题的所在,原来是一个计算表达式中用到了??运算符,才导致了这个错误,下面让我简单讲述一下. C# ?? 运算符 msdn上 ...

  7. Taglib、EL、OGNL

    Taglib.EL.OGNL 阅读目录 1. Taglib(tag library) 标签库 2. EL(Expression Language) 表达式 3. OGNL(Object-Graph N ...

  8. linux下mysql连接jar包的位置在哪里?

    linux下连接mysql数据库,肯定也会用到驱动jar包. 该jar包应该被置于jdk安装路径下jre文件夹lib目录的ext文件夹下.例如我的JDK安装路径为/usr/java/jdk1.6.0_ ...

  9. Keil中Memory Model和Code Rom Size说明

    C51中定义变量时如果省略存储器类型,Keil C51编译系统则会按编译模式SMALL.COMPACT和LARGE所规定的默认存储器类型去指定变量的存储区域,无论什么存储模式都可以声明变量在任何的80 ...

  10. hibernate安装和配置和第一个Hibernate应用

    ssh的各个版本要搭配好,struts2.3一般搭配hibernate4.x,我下的是4.3. Hibernate4的改动较大只有spring3.1以上版本能够支持,Spring3.1取消了Hiber ...