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. c#修改本地连接工具 ip地址,dns,网关,子网掩码

    //Form1类后台     #region 加载配置文件中的信息        /// <summary>        /// 加载配置文件中的信息        /// </s ...

  2. iOS 关于tableView中有多个textField,输入框被遮住的解决方法

    这里采用tableView整体上移的方法. 代码:(其中 60 为 单元格的高度) //点击输入框触发 - (void)textFieldDidBeginEditing:(UITextField *) ...

  3. javascript sort排序

    var arr = [5,32,28,66,2,15,3]; arr.sort(function(a1,a2){ return a1-a2; //a2-a1 输入倒序 }); console.log( ...

  4. 认识WebSocket理论篇

    本文转自http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/ HTML5作为下一代WEB标准,拥有许多引人注目的新特性,如Canvas.本 ...

  5. MYSQL操作的一些知识点,持续更新中····

    基本概念——库 1.数据库服务器:库——>表——>行/列 2.cmd下链接: mysql – uroot –proot 3.创建库:create database  php; 3.看数据库 ...

  6. dropdownlist绑定和选中

    最近在使用dropdownlist控件,对于这个控件,目前我知道的会使用两种方式去绑定数据,现在将这两种方式分享给大家: 现在是后台数据绑定 protected void BindCarID() { ...

  7. MongoDB监控一 mongostat

    mongostat命令                                                               mongostat可以提供mongod和mongos ...

  8. linux查找命令find

    -1 linux的查找命令有两个: locate find locate:有一个索引库,故速度快,但是新加入的一般不再索引库中,故可能无法查到 find:搜索速度慢,但是功能及其强大,可以追加命令动作 ...

  9. scp和pscp

    在linux中,我们常用scp命令传输文件: 如以下实例,我们想把当前服务器文件abc.sql传输到192.168.1.1服务器上,我们可以执行以下命令: scp /home/person/hww/a ...

  10. WCF不支持 ASP.NET 兼容性 解决办法

    错 误提示:无法激活服务,因为它不支持 ASP.NET 兼容性.已为此应用程序启用了 ASP.NET 兼容性.请在 web.config 中关闭 ASP.NET 兼容性模式或将 AspNetCompa ...