struts標簽的使用和配置
配置:
1 在struts-config.xml文件中加入(可以到示例中的struts-config.xml文件中復制)
<message-resources parameter="MessageResources" />
2 在示例的src下拷貝MessageResources.properties文件到項目src下
3 在頁面引入就可使用
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
說明:第1,2步為struts的國際化資源束文件引入,第3為標簽引入
-----------------------------------------------------------------------------
Bean標記
bean:define
從已有的變量或者變量的屬性來定義一個新的變量。
<bean:define id="新定義的變量名" scope="原變量的scope" name="原變量名" toScope="新定義變量的scope"></bean:define>
<bean:define id="新定義的變量名" scope="原變量的scope" name="原變量名" property="原變量的屬性名" toScope="新定義變量的scope"></bean:define>
bean:write
<bean:write scope="變量的scope" name="變量名" property="變量的屬性名" filter="是否按html格式輸出(默認true為文本輸出)" format="數字(###,###.0000)日期(yyyy-MM-dd HH:mm:ss)"/>
結構數據中多重屬性可用"."作導航取出來
bean:message
相當于jstl中<fmt:message>(國際化標簽)
1 定義資源文件
com.itcast.ApplicationResources.properties
com.itcast.ApplicationResources_zh_CN.properties
2 在struts-config中添加:
<message-resources parameter="ApplicationResources" key="myKey" />
3 頁面中使用
<bean:message bundle="myKey" key="userName"/>
<bean:message bundle="myKey" key="password"/>
bean:size標簽
--------------------------------------------------------------
logic標記
logic:empty/login:notEmpty 判斷對象是否為空
<logic:empty name="對象名" property="屬性名" scope="對象的scope">
為空<br>
</logic:empty>
logic:notEmpty 判斷對象是否不為空
<logic:notEmpty name="對象名" property="屬性名" scope="對象的scope">
不為空<br>
</logic:notEmpty>
logic:present 判斷對象是否存在(用方同上)
logic:notPresent
----------------------------------------------||
例子:
request.setAtrribute("attr1",null);
request.setAtrribute("attr2","");
request.setAtrribute("attr3",new ArrayList());
<logic:empty name="attr1">
11<br>
</logic:empty>
<logic:notEmpty name="attr1">
12<br>
</logic:notEmpty>
<logic:present name="attr1">
13<br>
</logic:present>
<logic:notPresent name="attr1">
14<br>
</logic:notPresent>
<logic:empty name="attr2">
21<br>
</logic:empty>
<logic:notEmpty name="attr2">
22<br>
</logic:notEmpty>
<logic:present name="attr2">
23<br>
</logic:present>
<logic:notPresent name="attr2">
24<br>
</logic:notPresent>
<logic:empty name="attr3">
31<br>
</logic:empty>
<logic:notEmpty name="attr3">
32<br>
</logic:notEmpty>
<logic:present name="attr3">
33<br>
</logic:present>
<logic:notPresent name="attr3">
34<br>
</logic:notPresent>
結果:
11空
14不存在
21空
23存在
31空
33存在
-----------------------------------------||
html:equal/html:notEqual
html:greaterEqual大于等于
html:greaterThan大于
html:lessEqual小于等于
html:lessThan小于
-----------------------------------------||
logic:iterate(循環)
name:對應的bean,是一個集合類型
property:對應的集合類型的屬性
scope:變量的scope
id:臨時變量名
offset:循環起始位置
indexId:集合中當前無素的下標
length:控制長度
單循環
<logic:iterate id="username" scope="request" name="對應的bean,是一個集合類型">
output every username:${username }<br>
</logic:iterate>
雙循環
<logic:iterate id="user" scope="request" name="list" offset="2" indexId="i">
${user.username }<br>
<logic:iterate id="love" name="user" property="loves">
${love }
</logic:iterate><br>
</logic:iterate><br>
logic:
tiles標記
----------------------------------------------------------------
html標簽
<html:form action="/login" method="post">
username:<html:text property="username" value="123"/>
password:<html:password property="password"/>
sex:<html:radio property="sex" value="0" />男
<html:radio property="sex" value="1" />女
likes:<html:checkbox property="0" value="0">吃飯</html:checkbox>
<html:checkbox property="0" value="1">吃飯</html:checkbox>
xueli:<html:select property="xueli">
<html:option value="0">小學</html:option>
<html:option value="1">小學</html:option>
<html:optionsCollection property="qxlist" label="qx" value="qxid"/>
//<html:optionsCollection name="qxlist" label="qx" value="qxid"/>
1.
</html:select>
<html:submit value="提交"/>
</html:form>
posted on 2009-11-30 08:14
junly 閱讀(678)
評論(0) 編輯 收藏 所屬分類:
struts2/struts1.3/JSF