- 浏览: 637085 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
spring_springmvc:
java程序语言学习教程 地址http://www.zuida ...
java.math.BigDecimal类的用法 -
tuspark:
文章写的挺详细了,但是感觉太乱了,真不如这篇文章: BigDe ...
java.math.BigDecimal类的用法 -
u010040765:
感谢楼主分享,写的很详细,很容易看懂
Struts2中iterator标签遍历map总结 -
若无勇气终将褪去:
[flash=200,200][url][list][*][/ ...
java.math.BigDecimal类的用法 -
若无勇气终将褪去:
...
java.math.BigDecimal类的用法
1.MapAction.java
Java代码
package com.zx.demo.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.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;
}
}
package com.zx.demo.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.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
Java代码
<%@ 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>
<s:iterator value="listMap" id="column">
<s:set name="total" value="#column.value.size"/>
<s:iterator value="#column.value" status="s">
<tr>
<s:if test="#s.first"><td rowspan="${total}"><s:property value="#column.key"/></td></s:if>
<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>
Java代码
package com.zx.demo.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.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;
}
}
package com.zx.demo.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import com.zx.demo.model.Product;
import com.zx.demo.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
Java代码
<%@ 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>
<s:iterator value="listMap" id="column">
<s:set name="total" value="#column.value.size"/>
<s:iterator value="#column.value" status="s">
<tr>
<s:if test="#s.first"><td rowspan="${total}"><s:property value="#column.key"/></td></s:if>
<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>
发表评论
-
struts 用if标签判断session是否存在
2016-12-06 20:20 811登录时设置session session.put(&quo ... -
struts2 s:property 用法
2016-03-05 14:15 9951,访问Action值栈中的普 ... -
<s:hidden>标签获取url中的参数
2016-03-05 11:29 1047假设URL传递的参数: url="adminIn ... -
struts条转后,js、css失效问题
2015-08-31 20:58 0最近遇到了一个奇怪的问题,Struts2进行完处理后跳转到其他 ... -
<s:iterator>各种遍历用法
2015-08-31 20:43 0<s:iterator>各种遍历用法 转自:ht ... -
ibatis连接oracle11G报错,原因是ojdbc.jar包的bug
2015-03-21 11:59 1111ibatis连接oracle11G报错,原因是ojdbc.ja ... -
<s:iterator>的status属性
2015-03-16 21:49 1210<s:iterator>的status属性 &l ... -
struts2.2.3 web.xml配置变化
2011-12-24 16:09 1235<filter> <filter-n ... -
struts警告信息
2011-09-03 14:30 1258警告信息: 警告: No con ... -
struts2.2.3需要11个基本包
2011-09-03 14:22 2671struts2.2.3需要11个基本包: asm-3.1.ja ... -
struts2中常用Result类型的用法
2010-09-05 09:42 1352一、dispatcher (1)为缺省的result类型,一 ... -
java.lang.OutOfMemoryError: PermGen space及其解决方法
2010-08-01 18:07 1669java.lang.OutOfMemoryError: Per ... -
pageEncoding和charset
2010-07-31 21:03 1289pageEncoding是jsp文件本身的编码 conten ... -
<taglib>标签在web.xml文件中报错解决方法
2010-07-03 17:11 4454配置web.xml文件时,taglib ... -
如何将java中的属性值显示在文本框中?
2010-05-01 11:38 5125最近写了一个页面,一个文本框中要显示java的属性值 我知道可 ... -
JFreeChart教程(二)
2010-04-18 21:44 96121 一、JFreeChart获取。 JFree ... -
JFreeChart教程(一)
2010-04-18 21:42 1586一、jFreeChart产生图形的流程 创建一个数据源(da ... -
<s:checkbox>标签 嵌套循环
2010-01-09 13:29 1390<s:iterator value="subM ... -
Struts2 DoubleSelect标签的使用
2009-12-30 22:16 2375Struts2本身提供了级联下拉选择框标签,这对简化诸如省份/ ... -
struts2 标签的帮助提示tooltip
2009-12-30 21:14 1415在struts2中标签有个属性tooltip="帮助 ...
相关推荐
在Struts2中,`iterator`标签是用于遍历集合数据的重要工具,它可以用来迭代Map、List和数组等数据结构,以便在视图层进行展示。本篇文章将深入探讨`iterator`标签在遍历这些数据类型时的具体用法。 首先,我们来看...
Struts2是一个非常流行的...在Struts2中,我们可以使用OGNL(Object-Graph Navigation Language)表达式语言来遍历Map。 在Struts2中,Map遍历通常在JSP页面上进行,使用OGNL表达式。以下是一个简单的例子: ```jsp ...
### Struts2中Iterator标签的深入解析与应用 在Struts2框架中,`<s:iterator>`标签是一个非常强大的工具,用于在JSP页面上循环遍历集合数据,如列表(List)、数组、Map等。它允许开发者以一种动态且灵活的方式展示...
在Struts2框架中,开发Web应用时常常需要在JSP页面与Action之间传递数据,以...通过以上步骤,我们可以高效地在Struts2中处理并展示集合数据。理解和掌握这一流程,对于提升Web应用的开发效率和质量有着显著的帮助。
`<s:iterator>`是Struts2中的一个标签,用于迭代集合或者数组中的元素。在处理Map时,我们可以使用这个标签来迭代键值对,并在JSP页面上显示它们。 在描述中提到的"嵌套Map"是指Map的值本身还是另一个Map。这种结构...
`s:iterator`标签是Struts2中最常用的遍历集合的标签。它的主要属性包括: - **value**:指定要遍历的集合,可以是数组、列表或Map类型的对象。 - **id**:为每个遍历元素设置一个临时变量名。 - **status**:提供...
在Struts2框架中,`iterator`标签是一个非常重要的组件,用于遍历各种集合对象,如List、Map等。在上述描述中,开发者遇到了一个关于`iterator`标签嵌套使用的问题,涉及到`LinkedHashMap`存储的数据结构。让我们...
遍历Map集合是常见的操作,可以用于打印、处理或检查Map中的数据。下面我们将详细讲解几种遍历Map集合的方法。 首先,我们来看普通Java类中的遍历方式: 1. **遍历键集合**:Map集合提供了keySet()方法,返回一个...
`s:iterator`标签是Struts 2 提供的一个迭代标签,它允许开发者遍历任何可迭代的对象,如数组、集合或Map。在描述中提到的场景,这个标签用于遍历一个数据集,然后为每个元素创建一个`<s:checkbox>`标签。 `s:...
在Struts2框架中,标签库是其一大特色,它提供了丰富的自定义标签,使得开发者能够更加便捷地创建动态页面。这些标签极大地简化了JSP页面的编写,提高了代码的可读性和可维护性。 1. **Struts2核心标签库**: - `s...
在Struts2中,OGNL(Object-Graph Navigation Language)是默认的表达式语言,用于处理数据绑定、属性访问以及视图层的数据呈现。本文将深入讲解如何使用OGNL遍历Map对象,以展示Struts2在处理复杂数据结构时的灵活...
Struts2标签遍历详解 Struts2标签遍历是Struts2框架中的一个重要组件,用于在JSP页面中遍历集合中...总结,Struts2标签遍历提供了多种方式来遍历集合中的元素,并提供了多种属性来获取当前迭代的索引信息和元素信息。
Struts 2 标签库(文档手册) Tags-API-CLSW-JSP <%@ taglib prefix="s" uri="/struts-tags" %> 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. <s:a href=""></s:a>-...
`<s:iterator>`标签是Struts2中最常用的标签之一,它用于迭代任何可迭代的对象,包括List和Map。基本语法如下: ```jsp <s:iterator value="collection" var="item"> <!-- 迭代体 --> </s:iterator> ``` ...
在Struts2中,也可以使用 `<s:iterator />` 标签遍历Map对象。Map对象中有几对key-value就迭代几次,分别使用 `<s:property value="key"/>` 和 `<s:property value="value"/>` 。 四、iterator的value iterator的...
在Struts2中,标签库是其核心特性之一,它们为开发者提供了便利的方式来构建动态用户界面,无需深入HTML和JavaScript的底层细节。在本篇中,我们将深入探讨Struts2的标签应用及其在实际开发中的使用。 首先,了解...
10. **s:iterator标签**:用于迭代集合,常用于遍历列表、数组或Map,可以在循环内部嵌套其他Struts2标签。 11. **s:property标签**:用于显示Action类属性的值,可以格式化输出,支持EL表达式。 12. **s:debug...
在 Struts2 中,`siterator` 标签是一种非常实用的标签,它允许开发者遍历各种类型的集合,如数组、列表、Map 等,并进行迭代操作。同时,OGNL (Object-Graph Navigation Language) 是 Struts2 中的表达式语言,用于...
4. **遍历集合**:`<s:iterator>`是Struts2中非常实用的标签,用于遍历集合,如List、Set、Map等。通过`value`属性设置遍历的对象,`var`属性定义迭代变量名,`status`属性可以获取当前迭代的状态信息。 5. **条件...
本文将深入探讨Struts2中的标签及其使用实例。 一、Struts2标签库概述 Struts2标签库是基于JSP标准标签库(JSTL)的扩展,它包含了一系列用于构建动态Web应用的标签。这些标签分为两类:核心标签和主题标签。核心...