Exercise -Struts-Examples1.3.8
l Bean:cookie
取得某個cookie的值
<bean:cookie id="sess" name="JSESSIONID" value="JSESSIONID-IS-UNDEFINED" />
獲取名為“JSESSIONID”的cookie,并放入page范圍內。
<bean:write name="sess" property="value" />
在頁面上打印出cookie的屬性
其他方式:
<jsp:getProperty name="sess" property="value" /> javabean標簽
<%=((Cookie)(pageContext.getAttribute(“sess”))).getValue()%> pageContext方式
<%=sess.getValue()%> 變量取值的方式
l Bean:define
在page范圍內定義一個變量,值從另一個對象的某個簡單屬性獲取
<bean:define id="test1_long" name="test1" property="longProperty" />
可以通過bean:write,jsp:getProperty, <%=test1_long%> 獲得定義變量的值
只從另一個嵌套對象的屬性獲取
<bean:define id="test2_boolean" name="test2" property="nested.booleanProperty" />
l Bean:header
從http請求頭定義page范圍的變量
<bean:header id="head" name=" Accept-Language"/>
l Bean:include
把一個page內容讀入page范圍內的一個變量
<bean:include id="welcome" page="/welcome.jsp" />
l Bean:parameter
將一個請求里的參數讀入page范圍內的一個變量,如果沒有參數就拋異常JspException
<bean:parameter id="param1" name="param1"/>
l Bean:page
存儲java的隱式對象到page范圍內,隱式對象包括:pplication, config, request, response, or session
<bean:page id="cfg" property="config"/>
<bean:write name="cfg" property="servletName"/>
l Bean:resource
將web應用資源讀入到page范圍內。
<bean:resource id="webxml" name="/WEB-INF/web.xml" />
l Bean:size
將數組,集合,map的大小存入到page范圍內
<bean:size id="stringSize" name="bean" property="stringArray" />
l Bean:struts
將struts配置對象,form,forward,mapping對象讀入到page范圍內
<bean:struts id="cfg" mapping="/search"/>
l Bean:write
渲染一個對象到頁面
<bean:write name="test1.float" />
<bean:write name="test2" property="booleanProperty" />
<bean:write name="test3" property="intArray[1]"/>
<bean:write name="test5" property="nested.booleanProperty" />
<bean:write name="test7.double" format="#,000.00" />
<bean:write name="test7.date" formatKey="date.pattern" />
l html:cancel
輸出<input type=”submit”>,會觸發struts的cancel特征
<html:form action="/html-cancel-false">
<html:submit property="submit"/>
<html:reset/>
<html:cancel/>
</html:form>
與下面action的cancellable屬性有關
<action path="/html-cancel-false" name="testbean"
input="/html-cancel.jsp" cancellable="false"validate="true" forward="/welcome.do">
validate為true時,cancellable必須為true,否則有異常
l html:img
輸出<img>
<html:img page="/struts-power.gif" />
<html:img action="/html-img-action" />
<html:img page="/exercise/struts-power.gif" module="/"/>
l html:image
輸出<input type=”image”>
<html:image page="/struts-power.gif" />
<html:image page="/struts-power.gif" module="/validator"/>
l html:link
輸出<a>標簽,由基本url加query string構成
<html:link action="/html-link-submit">No modifications at all</html:link>
<html:link action="/html-link-submit?doubleProperty=321.321&longProperty=321321">Double and long via hard coded changes</html:link>
<html:link action="/html-link-submit" paramId="stringProperty" paramName="newValue">String via paramId and paramName</html:link>
<html:link action="/html-link-submit" paramId="booleanProperty" paramName="testbean" paramProperty="nested.booleanProperty">Boolean via paramId, paramName, and paramValue</html:link>
<html:link action="/html-link-submit" name="newValues">Float, int, and stringArray via name (Map)</html:link>
<html:link action="/html-link">
No modifications at all, but link to the default module.
</html:link>
<html:link action="/html-link?doubleProperty=321.321&longProperty=321321"
module="/exercise">
Double and long via hard coded changes (module)
</html:link>
<td colspan="4" align="center">
<html:link action="/html-link"
paramId="stringProperty" paramName="newValue">
String via paramId and paramName
</html:link>
<html:link action="/html-link"
paramId="booleanProperty"
paramName="testbean" paramProperty="nested.booleanProperty"
module="/exercise">
Boolean via paramId, paramName, and paramValue (module)
</html:link>
<html:link action="/html-link"
name="newValues">
Float, int, and stringArray via name (Map)
</html:link>
<html:link forward="relative">module welcome page</html:link>
<html:link action="/welcome" module="/">application welcome page (module="/")</html:link>
l html:multibox
輸出<input type=”checkbox”>
<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item"/>
</html:multibox>
<bean:write name="item"/>
</logic:iterate>
l html:rewrite
輸出url的字符串,但不做超鏈接
<html:rewrite
paramId="query"
paramName="queryObj"/>
l html:message
打印上下文里Globals.MESSAGE_KEY 對應的一個集合
<html:messages id="msg" property="category">
<li><bean:write name="msg"/></li>
</html:messages>
<html:messages id="msg">
<li><bean:write name="msg"/></li>
</html:messages>
l html:error
打印上下文里Globals.ERROR_KEY 對應的一個集合
<html:errors/>
<html:errors property="username"/>
l logic:equal notEqual
判斷= !=
<logic:equal name="bean" property="booleanProperty" value="<%= bool1 %>">equal</logic:equal>
<logic:notEqual name="bean" property="booleanProperty" value="<%= bool1 %>">notEqual</logic:notEqual>
l logic:greaterEqual greaterThan lessEqual lessThan
判斷>= > <= <
<logic:greaterEqual name="bean" property="stringProperty" value="<%= str1 %>">greaterEqual</logic:greaterEqual>
<logic:greaterThan name="bean" property="stringProperty" value="<%= str1 %>">greaterThan</logic:greaterThan>
<logic:lessEqual name="bean" property="stringProperty" value="<%= str1 %>">lessEqual</logic:lessEqual>
<logic:lessThan name="bean" property="stringProperty" value="<%= str1 %>">lessThan</logic:lessThan>
l logic:empty notEmpty
判斷是否為null或字符串長度為0
<logic:empty name="missingBean">empty</logic:empty>
<logic:notEmpty name="missingBean">notEmpty</logic:notEmpty>
l logic:forward redirect
兩種不同的跳轉頁面方式
<logic:forward name="logic-forward" />
<logic:redirect action="/logic-forward"/>
<logic:redirect forward="logic-forward"/>
<logic:redirect page="/logic-forward.do"/>
注:如果是link的話,由action的forward元素的redirect屬性決定
l logic:iterate
迭代一個數組或者集合
<logic:iterate id="element" name="bean" property="stringArray" indexId="index">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
l logic:match notMatch
判斷是否包含value值
<logic:match cookie="JSESSIONID" value="0">match</logic:match>
<logic:notMatch cookie="JSESSIONID" value="0">notMatch</logic:notMatch>
l logic:present notPresent
判斷是否存在,運行包裝的內容
<logic:present name="bean">present</logic:present>
<logic:notPresent name="bean">notPresent</logic:notPresent>