本文为原创,如需转载,请注明作者和出处,谢谢!
Struts Logic标签库包含了如下三类标签:
1. 循环标签:iterate标签。用于枚举数组、集合类型对象中的元素。
2. 条件处理标签:用于是否相等、比较大小等判断。这类标签有empty、equal 、greaterEqual、greaterThan、lessEqual、lessThan、match、messagesNotPresent、messagesPresent、notEmpty、notEqual、notMatch、notPresent、present。
3. 流控制标签:用于转向其他的页面。redirect和forward属性这类标签。
一、循环标签(iterate)
1. id:一个表示集合中的每一个元素的变量,被保存在page范围中。
2. name:一个数组或集合对象名,或是一个包含有getter方法的JavaBean。
3. property:如果name是一个JavaBean,那么property就是这个JavaBean的属性名。
4. indexId:循环过程中的索引(从0开始),相当于Java中在for循环中使用变量i来获得循环中每一项的索引。
5. offset:偏移量。也就是从数组或集合的第几个元素开始枚举。
6. length:从offset开始,要枚举的元数的个数。
7. scope:name变量保存的范围。如果不指定,
下面的例子演示了
在IE中输入如下的URL测试iterate.jsp:
http://localhost:8080/samples/iterate.jsp
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
二、条件处理标签 条件处理标签可分为如下三类: 2. 比较:equal,
lessThan, lessEqual, greaterThan和greaterEqual 3. 字符串匹配: match、notMatch
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
1. Test:
present、notPresent、empty、notEmpty、 messagesPresent、messagesNotPresent
所有的条件处理标签都有name和property属性。分别用来指定对象名和属性名。如下面的代码演示了
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> <logic:empty name="var">
var为空
logic:empty>
<logic:lessThan name="employee" property="age" value="18">
不符合工作年龄
logic:lessThan>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> <logic:redirect href="http://www.sina.com.cn"/>
关于Logic标签库的更详细的信息请读者参阅Struts的官方网站,URL如下:
http://struts.apache.org/1.2.9/userGuide/struts-logic.html
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12921506/viewspace-541473/,如需转载,请注明出处,否则将追究法律责任。