1. Struts2頁面開發中常用標簽使用說明
1.1.往action里傳值的使用方式:
<input name="userName" type="text" class="input6" size="15">
a. userName屬性需要在訪問的action中提供相應的屬性,并有SET/GET方法。
b. 可以不在訪問的action中提供相應的屬性,用request.getParameter(“userName”);1.2.顯示標簽 property 用于輸出指定值:
<s:property value=" userName "/> 當action返回到指定頁面是,可以通過該標簽顯示action中的屬性信息。(注 userName必須在action中存在,并有GET方法)。
1.3.往對象中傳值<s:textfield> 用于從頁面往action中的對象內傳值:
<s:text name="user. userName " id="username"/>
該標簽可以在頁面中向action中的實體對象內直接傳值。(注:在action中要存在user對象,并有SET/GET方法。)
1.4.判斷<s:if> </s:if> 用于在頁面中判斷指定數據
<s:if test="userName == admin">…. </s:if>
<s:else>…. </s:else>
該標簽用于對指定的數據進行判斷,但指定的數據必須在action中存在。
1.5.迭代<s:iterator>用于將List、Map、ArrayList等集合進行循環遍歷
<s:iterator value="userList" id="user" status="u">
<s:property value="userName"/></a>
</s:iterator>
該標簽用于將userList集合中的元素進行循環,用過property進行顯示集合中的指定元素值。
1.6.URL地址標簽,<s:url>用于生成一個URL地址,可以通過URL標簽指定的<s:param>子元素向URL地址發送請求參數
<s:url action=" ">
<s:param name=" " value=""></s:param>
</s:url>
其中action為請求地址,param子元素為地址后面所帶的參數。
1.7.超鏈接 <a href >一般和<s:url>標簽一起使用,用于帶多個參數。
<a href="
<s:url action=" ">
<s:param name=" " value=""></s:param>
<s:param name=" " value=""></s:param>
<s:param name=" " value=""></s:param>
</s:url>">
超鏈接</a>
1.8.set標簽,用于將某個值放入指定的范圍內。例如application,session等。
<s:set name="user" value="userName" scope=”request”/>
將user值放入request范圍內。
2. Struts2頁面開發中常用標簽使用規范:
1.1.通過<input name="userName" type="text" class=" " size="15">
往action中傳值,action中要有相應的屬性,并提供SET/GET方法。
(在數量少時可以使用request.getParameter(“userName”);)
1.2.在頁面顯示action傳來的數據,使用property標簽。需要顯示的數據從action中獲得。
1.3.往action中的實體對象內傳值,使用textfield標簽。
1.4.在頁面中判斷指定值使用<s:if>標簽。判斷數據從action中獲得。
1.5.在頁面中需要循環列表顯示的數據使用<s:iterator>標簽,列表數據從action中獲得。
1.6.URL地址和超鏈接可以使用<a href>和<s:url>,在傳多值時建議<a href>和<s:url>一起使用
posted on 2009-10-09 09:37
super_nini 閱讀(606)
評論(0) 編輯 收藏