新聞中心
一. Struts標(biāo)簽庫中的HTML標(biāo)簽

HTML標(biāo)簽庫主要用來顯示HTML元素,如果不用這種方法,你就必須用HTML標(biāo)簽來指定它們。從表面上看,這個標(biāo)簽庫很簡單。但是通過深入研究,我們就會發(fā)現(xiàn)它很強(qiáng)大。例如,它可以為我們在HTML表單的
一個特定輸入元素中放置重點內(nèi)容生成JavaScript,或為客戶端輸入驗證生成腳本。而且,你可以用它通過一行代碼來處理錯誤。然而,在將這個標(biāo)簽庫用于你的Struts應(yīng)用程序前,你需要做些簡單的準(zhǔn)備工作。
配置應(yīng)用程序來運(yùn)用標(biāo)簽庫
在運(yùn)用Struts HTML標(biāo)簽庫前,你需要通過三個步驟來配置一個Struts應(yīng)用程序。
1. 在部署描述符(web.xml文件)中注冊標(biāo)簽庫,告訴servlet容器有關(guān)Struts HTML標(biāo)簽庫的情況,以及在哪里可以找到標(biāo)簽庫的TLD文件,代碼如下:
/WEB-INF/struts-html.tld
< /TAGLIB-URI>/WEB-INF/struts-html.tld
< /TAGLIB-LOCATION>2. 要確定將struts-html.tld文件復(fù)制到WEB-INF目錄中。你不用擔(dān)心標(biāo)簽庫類文件,因為它們已經(jīng)包含在struts.jar文件中了。
3. 在運(yùn)用標(biāo)簽庫的每個JSP頁面中,插入下面的 指示符:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
HTML標(biāo)簽庫包含幾個很容易使用的獨立的標(biāo)簽:
< html:html>標(biāo)簽
< html:html>標(biāo)簽是HTML標(biāo)簽庫中最容易的標(biāo)簽。它有兩個屬性:locale和xhtml,兩者都不是必需的。
e.g. HelloWorld-html:
建立一個JSP頁面welcome.jsp,輸入如下內(nèi)容:
< %@ taglib uri="/WEB-INF/struts- html.tld" prefix="html" %>
< ?xml:namespace prefix = html />< html:html locale="true">
Hello World!
中的locale屬性在生成的HTML頁面中被轉(zhuǎn)換成了。生
成的結(jié)果取決于Struts應(yīng)用程序所位于的服務(wù)器的locale。如果你將應(yīng)用程序部署到一個不同locale的服務(wù)器,你不需要改變代碼。Locale會自動調(diào)整。
< html:base>標(biāo)簽
< html:base>標(biāo)簽顯示一個HTML元素,用一個href屬性表示所包含的JSP頁面的絕對位置。只有當(dāng)這個
標(biāo)簽是內(nèi)嵌在一個head標(biāo)簽部分時,它才有效。e.g. HelloWorld-base:
< %@ taglib uri="/WEB-INF/struts- html.tld" prefix="html" %>
< html:base>< /html:base>
Hello World!
< /html:html>
< html:base>標(biāo)簽會轉(zhuǎn)換成:
< BASE href="
< html:link>標(biāo)簽
< html:link>標(biāo)簽會生成一個超鏈接。
e.g. < html:link page="/index.jsp">Index< /html:link>
會轉(zhuǎn)換成:Index
< html:errors>標(biāo)簽
< html:errors>標(biāo)簽的易于使用性通常會掩蓋其真正的強(qiáng)大功能。通過一個簡單的< html:errors>< /html:errors>標(biāo)簽,你就可以在一個JSP頁面上顯示完全自定義的錯誤信息。這個標(biāo)簽檢查Request對象的屬性集合來查找一個reserved key。如果它找到一個reserved key,它就假設(shè)這個key是一個 String、或是一個String數(shù)組(它包含在模塊的MessageResources中查找的message keys)、或是類型為org.apache.struts.action.ActionErrors的一個對象。
如果在應(yīng)用程序資源中存在相應(yīng)的信息,那么就可以用下面這些可選的message keys:
errors.header:相應(yīng)的信息在錯誤信息的單獨列表前顯示。
errors.footer:相應(yīng)的信息在錯誤信息的單獨列表后顯示。
errors.prefix:相應(yīng)的信息在錯誤信息的單獨列表前顯示。
errors.suffix:相應(yīng)的信息在錯誤信息的單獨列表后顯示。
二. logic 標(biāo)簽
1、定義標(biāo)簽文件(web.xml)
/tags/struts-logic
/WEB-INF/struts-logic.tld
2、引用標(biāo)簽文件(jsp文件)
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
3、標(biāo)簽文件說明(struts-logic.tld)
(1)empty標(biāo)簽
類名:org.apache.struts.taglib.logic.EmptyTag
標(biāo)簽體:bodycontent=JSP
引用logic:empty
屬性 attribute:name,property,scope
功能:判斷對象的值是否為空
(2)equal
類名:org.apache.struts.taglib.logic.EqualTag
標(biāo)簽體:bodycontent=JSP
引用logic:equal
屬性 attribute:cookie,header,name,parameter,property,scope,value
功能:等于比較符
(3) forward
org.apache.struts.taglib.logic.ForwardTag
標(biāo)簽體:bodycontent=empty
引用logic:forward
屬性 attribute:name
功能:頁面導(dǎo)向,查找配置文件的全局forward
(4) greaterEqual
類名:org.apache.struts.taglib.logic.GreaterEqualTag
標(biāo)簽體:bodycontent=JSP
引用logic:greaterEqual
屬性 attribute:cookie,header,name,parameter,property,scope,value
功能:大于等于比較符
(5)greaterThan
類名:org.apache.struts.taglib.logic.GreaterThanTag
標(biāo)簽體:bodycontent=JSP
引用logic:greaterThan
屬性 attribute:cookie,header,name,parameter,property,scope,value
功能:大于比較符
(6) iterator
類名:org.apache.struts.taglib.logic.IterateTag
標(biāo)簽體:bodycontent=JSP
引用logic:iterator
屬性 attribute:collection,id,indexId,length,name,offset,property,scope,type
功能:顯示列表為collection的值(List ,ArrayList,HashMap等)
(7)lessEqual
類名org.apache.struts.taglib.logic.LessEqualTag
標(biāo)簽體:bodycontent=JSP
logic:lessEqual
屬性 attribute:cookie,header,name,parameter,property,scope,value
功能:小于等于比較符
(8)lessThan
類名:org.apache.struts.taglib.logic.LessThanTag
標(biāo)簽體:bodycontent=JSP
logic:lessThan
屬性 attribute:cookie,header,name,parameter,property,scope,value
功能:小于比較符
(9)match
類名:org.apache.struts.taglib.logic.MatchTag
標(biāo)簽體:bodycontent=JSP
引用logic:match
屬性 attribute:cookie,header,location,name,parameter,property,scope,value
功能:比較對象
(10)messagesNotPresent
類名:org.apache.struts.taglib.logic.MessagesNotPresentTag
標(biāo)簽:bodycontent=JSP
引用logic:messagesNotPresent
屬性 attribute:name,property,message
功能:ActionMessages/ActionErrors對象是否不存在
(11)messagePresent
類名:org.apache.struts.taglib.logic.MessagesPresentTag
標(biāo)簽:bodycontent=JSP
引用logic:messagePresent
屬性 attribute:name,property,message
功能:ActionMessages/ActionErrors對象是否不存在
(12)notEmpty
類名:org.apache.struts.taglib.logic.NotEmptyTag
標(biāo)簽:bodycontent=JSP
引用logic:notEmpty
屬性 attribute:name,property,scope
功能:比較對象是否不為空
(13)notEqual
類名:org.apache.struts.taglib.logic.NotEqualTag
標(biāo)簽:bodycontent=JSP
引用logic:notEqual
屬性 attribute:cookie,header,name,parameter,property,scope,value
(14)notMatch
類名:org.apache.struts.taglib.logic.NotMatchTag
標(biāo)簽:bodycontent=JSP
引用logic:notMatch
屬性 attribute:cookie,header,location,name,parameter,property,scope,value
功能:比較對象是否不相等
(15)notPresent
類名:org.apache.struts.taglib.logic.NotPresentTag
標(biāo)簽:bodycontent=JSP
引用logic:notPresent
屬性 attribute:cookie,header,name,parameter,property,role,scope,user
功能:request對象傳遞參數(shù)是否不存在
(16)present
類名:org.apache.struts.taglib.logic.PresentTag
標(biāo)簽:bodycontent=JSP
引用logic:present
屬性 attribute:cookie,header,name,parameter,property,role,scope,user
功能:request對象傳遞參數(shù)是否存在
(17)redirect
類名:org.apache.struts.taglib.logic.RedirectTag
標(biāo)簽:bodycontent=JSP
引用logic:redirect
屬性
attribute:anchor,forward,href,name,page,paramId,paramName,paramProperty,paramScope,property,
scope,transaction
功能;頁面轉(zhuǎn)向,可傳遞參數(shù)
【編輯推薦】
- 在Eclipse中開發(fā)struts應(yīng)用程序
- 手把手教你在Eclipse中配置開發(fā)Struts
- Eclipse下開發(fā)struts完整解決亂碼問題
- Struts相關(guān)背景介紹
- 使用Easy Struts for Eclipse開發(fā)Struts
網(wǎng)站欄目:Struts標(biāo)簽庫中的HTML標(biāo)簽
網(wǎng)站地址:http://www.5511xx.com/article/cccjjih.html


咨詢
建站咨詢
