Struts標籤樣本

來源:互聯網
上載者:User
1.html:link標籤

用法1:
<html:link page="/html-link.do" paramId="paramName" paramName="paramValue">Content</html:link> 其中paramValue是在page、request、session或application中的一個屬性名稱,一般為基礎資料型別 (Elementary Data Type),也可以為對象。

用法2:
<html:link page="/html-link.do" paramId="paramName" paramName="beanName" paramProperty="oneProperty">Content</html:link>

用法3:
<html:link page="/html-link.do" name="oneHashMap">Content</html:link> 其中name是在page、request、session或application中的一個屬性名稱,一般為Map。

用法4:
<html:link page="/html-link.do" name="beanName" property="oneHashMap">Content</html:link>

2.html:select標籤

用法1:(下拉式清單單選)
<html:select name="beanName" property="aPropertyForSelect" size="1">
<html:option value="aValue">aName</html:option>
<html:option value="bValue">bName</html:option>
</html:select>

<html:select name="beanName" property="aPropertyForSelect" size="1">
<html:optionsCollection name="beanName" property="aCollection" label="name" />
</html:select> 其中aCollection是一個集合類型的屬性,內含一個JavaBean(該Bean的實現必須符合一定的規則)。

用法2:(列表單選)
<html:select name="beanName" property="aPropertyForSelect" size="3">
<html:option value="aValue">aName</html:option>
<html:option value="bValue">bName</html:option>
<html:option value="cValue">cName</html:option>
<html:option value="dValue">dName</html:option>
</html:select>

<html:select property="aPropertyForSelect" size="3">
<html:optionsCollection name="beanName" property="aCollection" label="name" value="value"/>
</html:select> 其中aCollection是一個集合類型的屬性,內含一個JavaBean(該Bean的實現必須符合一定的規則)。

用法3:(列表多選)
<html:select multiple="true" name="beanName" property="aPropertyForSelect" size="3">
<html:option value="aValue">aName</html:option>
<html:option value="bValue">bName</html:option>
<html:option value="cValue">cName</html:option>
<html:option value="dValue">dName</html:option>
</html:select>

<html:select multiple="true" property="aArray" size="3">
<html:optionsCollection name="beanName" property="aCollection" label="name" value="value"/>
</html:select> 其中aCollection是一個集合類型的屬性,內含一個JavaBean(該Bean的實現必須符合一定的規則)。aArray是一個數組用來接受所有選中的選項。

3.bean:message標籤

<bean:message key="keyFromProperties"/>其中keyFromProperties是資源檔中的一個索引值。這個資源檔是在struts-config.xml檔案中由設定的。

Struts尋找屬性檔案的方式:
A、.properties副檔名是嵌在代碼中的,所以資源檔必須使用這個副檔名
B、Struts並不是單純去找application.properties檔案,而是首先找到application,然後加上底線"_",然後再加上localeKey(如zh,en),然後再加上.properties($filename_$locale.properties)。 如果這裡沒有找到和locale對應的資源檔,Struts就使用application.properties,如果這個檔案也沒找到,Struts會報告錯誤。
C、確定了檔案名稱之後,Struts使用了ClassLoader類的getResourceAsStream方法得到了一個InputStream
D、然後Struts使用了java.util.Properties類的load方法,將資源檔中的所有資源讀出放到了一個HashMap裡面
E、然後Struts就可以根據key值取出不同的message了
注釋:資源檔的編碼為ISO8859。

4.html:cancel標籤

<html:cancel>valueForDisplay</html:cancel>其中valueForDisplay是html中button的顯示名。該標籤用來取消當前的Form。使用<html:cancel />時在Action中典型的處理方法:
if (isCancelled(request)) {
return mapping.findForward("somewherewhencanceled");
}
表示如果cancel則跳轉的相應page。

5.logic:iterate標籤

<logic:iterate id="id" name="beanName" property="aCollection">
//do something here
<logic:iterate>
該標籤用來迭代一個集合。使用indexId可以得到當前的index,如下:
<logic:iterate id="id" indexId="i" name="beanName" property="aCollection">
<bean:write name="i"/> //這裡列印出了index的值
</logic:iterate>

6.html:checkbox標籤

<html:checkbox name="beanName" property="aPropertyName"/>

<html:checkbox name="beanName" property="aPropertyName">DisplayContent</html:checkbox>
其中aPropertyName一般為boolean類型的變數。get方法可以是getXXX,也可以是isXXX。

7.html:multibox標籤

<logic:iterate id="pairValue" name="beanName" property="collection">
<html:multibox property="values">
<bean:write name="pairValue" property="value"/>
</html:multibox>
<bean:write name="pairValue" property="name"/>
</logic:iterate>
其中collection是集合類型。values是一個數組,用來接受提交的value值。

8.html:text標籤

用法1:
<html:text property="aValue"/>
用法2:
<html:text name="beanName" property="aValue"/>

9.html:textarea標籤

用法1:
<html:textarea property="aValue" />
用法2:
<html:textarea name="beanName" property="aValue" />

10.html:radio標籤

用法1:
<html:radio property="aProperty" value="aValue"/>
用法2:
<html:radio name="beanName" property="aProperty" value="aValue"/>
其中aProperty的名字相同的被分為一組。
用法3:
<logic:iterate id="pairValue" name="beanName" property="collection">
<html:radio property="aProperty" idName="pairValue" value="value"/>
</logic:iterate>
其中aProperty用來接受提交的值。

11.html:form標籤

<html:form action="aAction"></html:form>

12.bean:header標籤

<bean:header id="agent" name="User-Agent"/>該標籤用來操作request的header,從header中讀出相關資訊。

13.logic:match標籤

用法1:
<logic:match header="User-Agent" value="Mozilla">Mozilla Browser</logic:match>
從header中取出User-Agent的值,然後與value的值匹配,匹配則顯示body,否則不顯示body。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.