struts logic標簽使用詳解
Logic 比較標簽(一)
1.<logic:equal>
判斷變量是否與指定的常量相等。例如:
?
?
?
?
?
2.<logic:greaterThan>
判斷常量變量是否與指定的常量不相等。
<html:link page="/greaterThan.jsp?test=123456">添加參數</html:link> //傳值
<logic:greaterThan value="12347" parameter="test">
?
</logic:greaterThan>
下面類似
3.<logic:greaterEqual>
判斷變量大小是否等于指定的常量。
4.<logic:lessThan>
判斷變量是否小于指定的常量。
5.<logic:lessEqual>
判斷變量是否小于等于指定的常量。
Struts logic標簽(二)
循環遍歷標簽<logic:iterate>
該標簽用于在頁面中創建一個循環,以次來遍歷數組、Collection、Map這樣的對象。在Struts中經常用到!
例如:
<%
String []testArray={"str0","str1","str2","str3","str4","str5"};
pageContext.setAttribute("test",testArray);
%>
<logic:iterate id="array" name="test">
?
</logic:iterate>
首先定義了一個字符串數組,并為其初始化。接著,將該數組存入pageContext對象中,命名為test1。然后使用logic:iterate標記的name屬性指定了該數組,并使用id來引用它,同時使用bean;write標記來將其顯示出來。
還可以通過length屬性指定輸出元素的個數,offset屬性指定從第幾個元素開始輸出。例如:
<logic:iterate id="array1" name="test1" length="3" offset="2">
<bean:write name="array1"/><br>
</logic:iterate>
Struts logic標簽(三)
<logic:match>
<logic:notmatch>
該標簽用于判斷變量中是否或者是否不包含指定的常量字符串。例如:
<%
?
%>
<logic:match value="hello" name="test">
?
</logic:match>
Match標記還有一個重要屬性,就是location屬性。location屬性所能取的值只有兩個,一個是"start",另一個是"end"。例如:
<logic:match value="hello" name="test" location="start">
?
</logic:match>
Struts logic存在標簽(四)
<logic:present>
<logic:notpresent>
<logic:messagePresent>
<logic:messageNotPresent>
<logic:present>和<logic:notpresent>標簽主要用于判斷所指定的對象是否存在;
例如:
<%
pageContext.setAttribute("test","testString");
%>
<logic:present name="test">
?
</logic:present>
<logic:present>和<logic:notpresent>標記有以下幾個常用屬性:
header屬性:?
parameter屬性:判斷是否存在parameter屬性指定的請求參數。
cookie屬性:?
name屬性:?
property屬性:和name屬性同時使用,當name屬性所指定的變量是一個JavaBean時,判斷property屬性所指定的對象屬性是否存在。
<%
?
?
%>
<logic:present cookie="name">
?
</logic:present>
<logic:messagePresent>和<logic:messageNotPresent>這兩個標記是來判斷是否在request內存在特定的ActionMessages或ActionErrors對象。它們有幾個常用的屬性:
name屬性:?
message屬性:message屬性有兩種取值。當其為true時,表示使用Globals.MESSAGE_KEY做為從request對象中獲取ActionMessages的key值,此時無論name指定什么都無效;當其為false時,則表示需要根據name屬性所指定的值做為從request對象中獲取ActionMessages的key
值,倘若此時未設置name屬性的值,則使用默認的Globals.ERROR_KEY。
property屬性:指定ActionMessages對象中某條特定消息的key值。
例如:
?
?
?
?
?
?
?
?
?
Struts logic判空標簽(五)
<logic:empty>
<logic:notEmpty>
該標簽用于判斷指定的字符是否為空。
例如:
?
?
?
?
?
?
?
Struts logic轉發和重定向標簽(六)
1.<logic:foward>轉發標簽
該標簽用于進行全局轉發,使用該標簽的頁面一般不再編寫其他內容,因為隨著轉發,頁面將跳轉,原頁面中的內容也沒有意義了。例如:
?
<logic:forward name="welcome"/>
?
2.<logic:redirect>重定向標簽
該標簽用于進行重定向。具有屬性:
href屬性:?
page屬性:?
forward屬性:該屬性與struts-config.xml中的<global-forward>內的子項相對應。即將頁面重定向到forward所指定的資源。
posted on 2009-07-16 23:51 IT追求者 閱讀(519) 評論(0) 編輯 收藏 所屬分類: struts