struts Taglib簡單標(biāo)簽介紹
Posted on 2009-03-04 19:51 鄭舒力 閱讀(1314) 評論(0) 編輯 收藏 所屬分類: struts 學(xué)習(xí)筆記struts Taglib屬于視圖端的技術(shù)
使用標(biāo)簽有如下優(yōu)點
一、易于使用,能直接代替在頁面上寫java腳本
二、便于重用
struts 標(biāo)簽的配置
1、在struts-config配置文件中加入標(biāo)簽 <message-resources parameter="MessageResources" />
2、引入taglib標(biāo)簽庫
加入<%@ taglib prefix="bean" uri="在struts-taglib.jar包下的META-INF文件夾的tld文件夾下找 到相應(yīng)標(biāo)簽庫的tld文件打開,把uri標(biāo)簽中的值復(fù)制到此處" %>
<bean:write>標(biāo)簽
相當(dāng)于jsp標(biāo)簽 <%= %> jsp內(nèi)置對象out.println()方法 做輸出使用
在相應(yīng)scope內(nèi)設(shè)置值,用<bean:write>標(biāo)簽取出。
examples:
取出普通字符串
<bean:write name="hello"/>
name屬性也就是在上一頁面setAttribute()的key。
以HTML文本形式做輸出
<bean:write name="hello" filter="false"/>
filter="false"文本按HTML形式取出
格式化日期形式輸出
<bean:write name="date" format="yyyy-mm-dd HH:mm:ss"/>
format屬性內(nèi)設(shè)置日期顯示的格式
格式化數(shù)字
<bean:write name="num" format="###,###.0000"/>
format屬性內(nèi)設(shè)置數(shù)字顯示的格式 數(shù)字顯示格式API在java.text.DecimalFormat中
對象結(jié)構(gòu)輸出
對象普通屬性輸出
<bean:write name="user" property="name"/>
property="name",引號內(nèi)設(shè)置屬性名,需要符合javaBean規(guī)范
對象結(jié)構(gòu)屬性輸出
<bean:write name="user" property="group.name"/>
property="group.name",使用.進行導(dǎo)航找到結(jié)構(gòu)相應(yīng)屬性.
<logic:empty><logic:notEmpty><logic:present><logic:notPresent>標(biāo)簽
這些標(biāo)簽主要用于進行屬性狀態(tài)的判斷
examples:












null值判斷為不存在
不存在同樣判斷為為空
空字符串判斷為空,空集合判斷為空
<logic:terate>迭代標(biāo)簽
<logic:iterate id="u" name="userList">
</logic:iterate>
對集合進行迭代,循環(huán)取出值放在變量u內(nèi)
examples:






