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. React react-ui-tree的使用

    公司需要做一个IDE,要做IDE当然少不了文件列表了.下面我就来展示一下刚刚研究的一个库. 下面是链接:https://react.rocks/example/react-ui-tree 至于如何导入 ...

  2. Java Timer触发定时器

    XML: <!-- Java Timer定时 --> <!-- <bean id="shortUrlTask" class=" com.sprin ...

  3. zoj3231 Apple Transportation(最大流)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Apple Transportation Time Limit: 1 Second ...

  4. 为js数组扩展方法

    (function(global,undefined){ //javascript冒泡排序,直接添加到基础类型Array的原型上 Function.prototype.method = functio ...

  5. 用H5实现微信的四个界面

    代码更新中

  6. JS设置获取cookies

    结合JavaScript权威指南,加上项目开发时在网上搜集的资料,整理了两种设置和获取cookie的方法. <script> //设置cookie  方法一function setCook ...

  7. 使用TypeScript实现简单的HTML5贪吃蛇游戏

    TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程.安德斯·海尔斯伯格,C#的首席架构师,已 ...

  8. Ubuntu14.0.4 64位 ADT 连接手机调试问题

    1:使用 lsusb 命令查看USB 设备 y@y:~$ lsusbBus 001 Device 002: ID 8087:8000 Intel Corp. Bus 001 Device 001: I ...

  9. LeetCode_Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...

  10. 外贸中MFQ

    MFQ = Mask Fee Quantity 退掩膜费量Masking charge USD 2000. MFQ 100k in the first year