Struts2之【控制標籤】

在使用控制標籤前,須要在jsp文件中引入標籤html

且常常與ognl、el表達式打搭配使用web

<%@ taglib prefix="s" uri="/struts-tags" %>

1.<s:if>

屬性:testapache

<!-- Action -->
private String framework = "Struts2"

<!-- JSP -->
<s:set name="webFramework" value="framework" />

//使用了ognl表達式
<s:if test="%{#webFramework=='Struts2'}">
    this is struts2
</s:if>
<s:elseif test="%{#webFramework=='Struts1'}">
    this is struts1
</s:elseif>
<s:else>
    other framework
</s:else>

2.<s:iterator>:迭代器

屬性jsp

-begin :從begin開始迭代(index)
    -end   :到end結束迭代(index)
    -value :被迭代的集合
    -id    :集合中的元素的id(Struts2.1.x中已被廢棄,用var來代替)
    -var   :集合中的元素
    -step  :每次步長,i = i + step
    -status:用於在IteratorStatus類中聲明名稱,迭代狀態

IteratorStatus類用於獲取迭代的狀態信息:[索引]、[計數]、[第一個]、[最後]、[奇]、[偶]等this

int getCount()    返回當前迭代了幾個元素   status.count 
int getIndex()    返回當前元素索引         status.index
boolean isFirst() 當前是否第一個元素       status.first
boolean isLast()  當前是否最後元素         status.last
boolean isEven()  固然的索引是否偶數       status.even
boolean isOdd()   當前元素索引是否奇數     status.odd

具體例子請參照iteratorcode

3.其餘

其餘:http://struts.apache.org/docs/tag-reference.htmlhtm

相關文章
相關標籤/搜索