Iterate主要用来处理在页面上输出集合类,集合一般来说是下列之一:
1、 java对象的数组
2、 ArrayList、Vector、HashMap等
该标记的功能强大,在Struts应用的页面中经常使用到。
iterate标记 :
id 脚本变量的名称,它保存着集合中当前元素的句柄。
name 代表了你需要叠代的集合,来自session或者request的属性。
type 是其中的集合类元素的类型
bean的write标记是用来将属性输出的,name用来匹配iterate的id,property用来匹配相应类的属性
1、对数组进行循环遍历
<table width="100%">
<logic:iterate type=" example.User ">
<tr><td width="50%">
name: <bean:write property="name"/>
<td/><td width="50%">
password: <bean:write property="password"/>
</td>
</tr>
</logic:iterate>
</table>
另外,还可以通过length属性来指定输出元素的个数,offset属性指定了从第几个元素开始输出。
<%
String[] testArray={"str1","str2","str3"};
pageContext.setAttribute("test",testArray);
%
<logic:iterate id="show" name="test">
<bean:write name="show"/>
</logic:iterate>
<br>
<logic:iterate id="show" name="test" length="2" offset="1">
<bean:write name="show"/>
</logic:iterate>
结果:
str1
str2
str3
str2
str3
另外,该标记还有一个indexId属性,它指定一个变量存放当前集合中正被访问的元素的序号
<logic:iterate length="2" offset="1" indexId="number">
<bean:write name="number"/>:<bean:write name="show"/>
</logic:iterate>
其显示结果为:
1:str2
2:str3
2 对HashMap进行循环遍历
程序代码<%
HashMap countries=new HashMap();
countries.put("country1","中国");
countries.put("country2","美国");
countries.put("country3","英国");
countries.put("country4","法国");
countries.put("country5","德国");
pageContext.setAttribute("countries",countries);
%>
<logic:iterate id="country" name="countries">
<bean:write name="country" property="key"/>:
<bean:write name="country" property="value"/>
</logic:iterate>
在bean:write中通过property的key和value分别获得HaspMap对象的键和值。其显示结果为:
country5:德国
country3:英国
country2:美国
country4:法国
country1:中国
由结果可看出,它并未按添加的顺序将其显示出来。这是因为HaspMap是无序存放的。
3、嵌套遍历
程序代码:
<%
String[] colors={"red","green","blue"};
String[] countries1={"中国","美国","法国"};
String[] persons={"乔丹","布什","克林顿"};
ArrayList list2=new ArrayList();
list2.add(colors);
list2.add(countries1);
list2.add(persons);
pageContext.setAttribute("list2",list2);
%>
<logic:iterate id="first" name="list2" indexId="numberfirst">
<bean:write name="numberfirst"/>
<logic:iterate id="second" name="first">
<bean:write name="second"/>
</logic:iterate>
<br>
</logic:iterate>
分享到:
相关推荐
jsp脚本和<logic:iterate>标签:实现循环和分支逻辑 jsp脚本和<logic:iterate>标签:实现循环和分支逻辑 jsp脚本和<logic:iterate>标签:实现循环和分支逻辑
我就是靠这个文档实现logic:iterate的循环的 struts 标签 logic:iterate使用 logic:iterate <br>第一页 是struts官方的说明, 第二页 是个例子 第三页 是我实现的arrayList放入标签的方法。 这是页面...
1. Map里存放的是bean时 <br><logic:iterate id="destMap" name="srcMap"> <br> <bean:define id="bean" name="destMap" property="value" /> <br> <bean:write name="bean" property="name" /> <br></...
logic:iterate 产生问题的图
Iterate主要用来处理在页面上输出集合类,集合一般来说是下列之一: 1、 java对象的数组 2、 ArrayList、Vector、HashMap等
Struts Logic标签Struts Logic标签Struts Logic标签Struts Logic标签Struts Logic标签
<logic:iterate id="tr" name="grid" indexId="index2"> <html:link action="/jsp/office/exchange/preModifyExchangeDoc" paramId="exchangeDocOID" paramName="tr" paramProperty="key"> ...
struts标签库 文章目录 bean:cookie 2 bean:define 3 bean:header 4 ...logic:iterate 21 logic:present 23 logic:messagesPresent 23 logic:empty 24 logic:match 24 logic:equal 25 logic:forward 26 总结 26
struts-logic iterate标签学习指南 这标签还不错
怎么将利用DWR调用JAVA类方法所返回的ArrayList数组 赋值给 logiciterate 迭代器?.txt怎么将利用DWR调用JAVA类方法所返回的ArrayList数组 赋值给 logiciterate 迭代器?.txt怎么将利用DWR调用JAVA类方法所返回的...
We live in an age of unparalleled opportunity for innovation. We're building more products than ever before, but most of them fail--not because we can't complete what we set out to build, but because ...
本文详细介绍了如何在Struts中实现查询结果分页显示,logic:iterate 在分页里的用法的文章专题。
ibatise中关于iterate的用法的例子
<logic:iterate id="temp" name ="list"> <td><bean:write name="temp" property="userName"/> <td><bean:write name="temp" property="pwd"/> <td><bean:write name="temp" property=...
NULL 博文链接:https://364232252.iteye.com/blog/2369137
Struts Logic标签库中包含的标签列表 Tag name Description empty 如果标签parameter,propertie等属性所指定的变量值为null或空字符串,则处理标签包含的内容 equal 如果标签parameter,propertie等属性所指定的...
16.3.4、<logic:iterate>标签 16.3.5、重定向标签:<logic:redirect> 16.4、Html标签 16.4.1、<html:form>标签 16.4.2、<html:text>与<html:password>标签 16.4.3、<html:radio>标签 ...
16.3.4、<logic:iterate>标签 16.3.5、重定向标签:<logic:redirect> 16.4、Html标签 16.4.1、<html:form>标签 16.4.2、<html:text>与<html:password>标签 16.4.3、<html:radio>标签 16.4.5、<html:...
16.3.4、<logic:iterate>标签 16.3.5、重定向标签:<logic:redirect> 16.4、Html标签 16.4.1、<html:form>标签 16.4.2、<html:text>与<html:password>标签 16.4.3、<html:radio>标签 ...
16.3.4、<logic:iterate>标签 16.3.5、重定向标签:<logic:redirect> 16.4、Html标签 16.4.1、<html:form>标签 16.4.2、<html:text>与<html:password>标签 16.4.3、<html:radio>标签 ...