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. HQL查询语言——转载(http://www.cnblogs.com/20gg-com/p/6045739.html)

    Hibernate查询语言(HQL)是一种面向对象的查询语言,类似于SQL,但不是对表和列操作,HQL适用于持久对象和它们的属性. HQL查询由Hibernate转换成传统的SQL查询,这在圈上的数据 ...

  2. [BUG集] android 安卓项目中ORMLITE框架 Must specify one of id, generatedId, and generatedIdSequence with Id

    使用ORM框架ORMLITE有一段时间,今天在操作一个对象的时候,重新运行报错如下: Must specify one of id, generatedId, and generatedIdSeque ...

  3. stackView的隐藏与显示注意事项

    1.想要通过变换stackView的y值来让stackView显现/隐藏,同时让其中的button能点击响应,得用topCons 2.导航栏的tinBar要设置为非透明状态

  4. 因为相同类型的其他实体已具有相同的主键值。在使用 "Attach" 方法或者将实体的状态设置为 "Unchanged" 或 "Modified" 。。。

    因为相同类型的其他实体已具有相同的主键值.在使用 "Attach" 方法或者将实体的状态设置为 "Unchanged" 或 "Modified&quo ...

  5. 对于资源上MissingScript的清理方案讨论

    Unity工程随着复杂度的提升,常会有Prefab上的脚本丢失的情况,如下图所示: 首先失去关联的脚本,是没有线索找到原来是什么文件的,那么有没有办法批处理将这些MissingScript进行一下清理 ...

  6. pomelo获取客户端IP

    代码: Handler.prototype.getClientIp = function(msg, session, next) { var ip = session.__session__.__so ...

  7. Yii2的深入学习--yii\base\Object 类

    之前我们说过 Yii2 中大多数类都继承自 yii\base\Object,今天就让我们来看一下这个类. Object 是一个基础类,实现了属性的功能,其基本内容如下: <?php namesp ...

  8. Spring集成MyBatis完整示例

    该文详细的通过Spring IOC.MyBatis.Servlet.Maven及Spring整合MyBatis的等技术完成一个简单的图书管理功能,实现图书列表.删除.多删除.编辑.新增功能.梳理前面学 ...

  9. SQL Server安全(10/11):行级别安全(Row-Level Security)

    在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...

  10. Asp.Net 高性能ORM框架 SqlSugar.ORM 2.8

    3.0最新API: http://www.cnblogs.com/sunkaixuan/p/5911334.html 1.前言/Preface SqlSugar从去年到现在已经一年了,版本从1.0升到 ...