Student.java

package action;

public class Student {

    private Long sid;
private String name; public Student() {
// TODO Auto-generated constructor stub
}
public Student(Long sid,String name) {
this.sid=sid;
this.name=name;
}
public Long getSid() {
return sid;
}
public void setSid(Long sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

ClassHelloAction.java

package action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class ClassHelloAction extends AbstractAjaxAction { private String message;
private List<String> names;
private List<Student> stus;
private Map<String, Object> map;
private Map<String,List<Student>> stuMaps;
private List<Map<String,Student>> listMap; public List<Map<String, Student>> getListMap() {
return listMap;
} public void setListMap(List<Map<String, Student>> listMap) {
this.listMap = listMap;
} public Map<String, List<Student>> getStuMaps() {
return stuMaps;
} public void setStuMaps(Map<String, List<Student>> stuMaps) {
this.stuMaps = stuMaps;
} public List<Student> getStus() {
return stus;
} public Map<String, Object> getMap() {
return map;
} public void setMap(Map<String, Object> map) {
this.map = map;
} public void setStus(List<Student> stus) {
this.stus = stus;
} public List<String> getNames() {
return names;
} public void setNames(List<String> names) {
this.names = names;
} public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} public String execute() throws Exception { this.stuMaps=new HashMap<String, List<Student>>();
List<Student> list1=new ArrayList<Student>();
list1.add(new Student(1L,"aa"));
list1.add(new Student(2L,"bb"));
list1.add(new Student(3L,"cc"));
list1.add(new Student(4L,"dd")); List<Student> list2=new ArrayList<Student>();
list2.add(new Student(1L,"qq"));
list2.add(new Student(2L,"ww"));
list2.add(new Student(3L,"ee"));
list2.add(new Student(4L,"rr"));
//List<Student>
stus=new ArrayList<Student>();
stus.addAll(list1);
stus.addAll(list2); //Map<String,Object>
this.map=new HashMap<String, Object>();
map.put("1", "广州");
map.put("2", "珠海");
map.put("3", "东莞");
map.put("4", "佛山"); //Map<string,List<Student>>
stuMaps.put("一班", list1);
stuMaps.put("二班", list2); //List<Map<String,Student>>
this.listMap=new ArrayList<Map<String,Student>>();
Map<String,Student> map1=new HashMap<String, Student>();
map1.put("1号", new Student(1L,"鸣人"));
map1.put("2号", new Student(2L,"佐助"));
Map<String,Student> map2=new HashMap<String, Student>();
map1.put("3号", new Student(3L,"路飞"));
map1.put("4号", new Student(4L,"索隆"));
listMap.add(map1);
listMap.add(map2); return "success"; } }

1、遍历Map<String,Object>

<div style="float: left; border:thin solid;" >
        <p>遍历Map&lt;String,Objecg&gt;</p>
        <ul>
            <s:iterator value="map" id="id">
                <li><s:property value="#id.key" />:<s:property
                        value="#id.value" /></li>
            </s:iterator>
        </ul>
    </div>

2、遍历Map<String,List<Student>>

<div style="float: left;border: thin solid;">
        <p>遍历Map&lt;String,List&lt;Student&gt;&gt;</p>
        <ul>
            <s:iterator value="stuMaps" id="id" status="st">

<li><s:property value="#id.key" />: <s:select list="#id.value"
                        id="stu" listKey="sid" listValue="name"></s:select></li>

</s:iterator>
        </ul>
    </div>

3、遍历List<Map<String,Student>>

<div style="float: left;border:thin solid;">
        <p>遍历List&lt;Map&lt;String,Student&gt;&gt;</p>
        <ul>
            <s:iterator value="listMap" id="map" status="st">
                <s:iterator value="#map" id="mk" status="sa">
                    <li><s:property value="#mk.key" />:<s:property
                            value="#mk.value.name" /></li>
                </s:iterator>
            </s:iterator>
        </ul>
    </div>

4、index.jsp页面效果:

使用Struts2标签遍历集合的更多相关文章

  1. struts2标签 遍历map集合

    首先我们来构造几个map集合.    假设如下代码 都是在ssh配置环境下搭建好,(至少struts2开发环境搭建好) (1).java 代码          下面的student对象包含的字段为 ...

  2. Struts2标签遍历List<Map<String,String>>

    <s:if test="resultList != null && resultList.size() > 0"> <s:iterator  ...

  3. jquery遍历集合&数组&标签

      jquery遍历集合&数组的两种方式 CreateTime--2017年4月24日08:31:49Author:Marydon 方法一: $(function(){ $("inp ...

  4. JSTL详解(常用标签以及c:forEach遍历集合)

    JSTL标签 一. JSTL的简介 1. 什么是JSTL 2. JSTL常用标签库 3. JSTL使用步骤 二. 核心标签库常用标签 1. c: set 标签 2. c: out 标签 3. c: i ...

  5. 用struts2标签如何从数据库获取数据并在查询页面显示。最近做一个小项目,需要用到struts2标签从数据库查询数据,并且用迭代器iterator标签在查询页面显示,可是一开始,怎么也获取不到数据,想了许久,最后发现,是自己少定义了一个变量,也就是var变量。

    最近做一个小项目,需要用到struts2标签从数据库查询数据,并且用迭代器iterator标签在查询页面显示,可是一开始,怎么也获取不到数据,想了许久,最后发现,是自己少定义了一个变量,也就是var变 ...

  6. struts2标签

    一.通用标签 1.property     Name Required Default Evaluated Type Description default false   false String ...

  7. Struts2标签简介

    Struts2标签简介 Struts2标签的优势 标签库简化了用户对标签的使用 结合OGNL使用,对于集合.对象的访问功能非常强大 提供可扩展的主题.模板支持,极大简化了视图页面的编写 不依赖任何表现 ...

  8. Struts2标签库

    一. 写jsp页面的时候,在struts2中,用的是s标记,先引入标记: <%@ taglib prefix="s" uri="/struts-tags" ...

  9. Struts2 标签库讲解

    要使用Struts2的标签,只需要在JSP页面添加如下一行定义即可: <%@ taglib prefix="s" uri="/struts-tags"%& ...

随机推荐

  1. JDBC操作数据库,第一:jsp插入mysql数据库,坎坷摸索分享

    JSP连接数据库,坎坷摸索了好久,现在终于做好了,分享一下,希望对更多热爱编程学习的人有所帮助!!!谢谢 第一:首先准备的就是已经安装好Mysql,这里不做多叙述,百度可以做到. 然后在mysql数据 ...

  2. springSide部署出现AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public!

    AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Sp ...

  3. Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理

    在v6.2开始后,需要设置<requires-namespaced-parameters>false</requires-namespaced-parameters>  来避免 ...

  4. 面向对象tab栏例子分析

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. SSIS连接SAPBI

        SSIS默认的连接管理器是没有连接到Oracle或SAPBI的,因此如果希望SSIS调用SAP RFC的话,可以使用微软提供的连接管理器插件.     有关这一点的详细信息可以参考MSDN的官 ...

  6. 邻接矩阵有向图(三)之 Java详解

    前面分别介绍了邻接矩阵有向图的C和C++实现,本文通过Java实现邻接矩阵有向图. 目录 1. 邻接矩阵有向图的介绍 2. 邻接矩阵有向图的代码说明 3. 邻接矩阵有向图的完整源码 转载请注明出处:h ...

  7. 单机redis 主从实例

    环境windows xp sp3 1.redis 安装 redis windows安装文件下载地址:http://code.google.com/p/servicestack/wiki/RedisWi ...

  8. Mac OSX Java 编译时乱码问题

    由于是新系统,之前没有配置过导致今天javac编译的时候发现再iterm和Terminal中显示的是乱码,后来在网上找到解决方法,现在共享一下: 方法一: 在iterm2/Terminal中输入: c ...

  9. Windows Azure Service Bus (3) 队列(Queue) 使用VS2013开发Service Bus Queue

    <Windows Azure Platform 系列文章目录> 在之前的Azure Service Bus中,我们已经介绍了Service Bus 队列(Queue)的基本概念. 在本章中 ...

  10. JS根据身份证号码算年龄

    如果把身份证号码传到页面上,在前端页面获取年龄就需要用到JS脚本了: function GetAge(identityCard) { var len = (identityCard + "& ...