<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大漠駝鈴

    置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
    Java,Php,Shell,Python,服務(wù)器運(yùn)維,大數(shù)據(jù),SEO, 網(wǎng)站開發(fā)、運(yùn)維,云服務(wù)技術(shù)支持,IM服務(wù)供應(yīng)商, FreeSwitch搭建,技術(shù)支持等. 技術(shù)討論QQ群:428622099
    隨筆 - 238, 文章 - 3, 評(píng)論 - 117, 引用 - 0
    數(shù)據(jù)加載中……

    Struts2.0標(biāo)簽庫(kù)(二)數(shù)據(jù)標(biāo)簽[轉(zhuǎn)]

    Struts2提供了大量豐富的標(biāo)簽供使用,它不再像Struts1中一樣,將種類標(biāo)簽進(jìn)行分門列別,但可以根據(jù)其使用的用途用以區(qū)別。本文通過對(duì)Struts2中數(shù)據(jù)標(biāo)簽的學(xué)習(xí),來對(duì)Struts2中標(biāo)簽的學(xué)習(xí)起到一個(gè)拋磚引玉的作用。文中將介紹Action標(biāo)簽、Bean標(biāo)簽、Data標(biāo)簽、Include標(biāo)簽、Param標(biāo)簽、Set標(biāo)簽、Text標(biāo)簽、Property標(biāo)簽等標(biāo)簽。
     一、<s:action>標(biāo)簽

    Action標(biāo)簽,顧名思義,是用來調(diào)用Action的標(biāo)簽,在JSP中頁(yè)面中,可以指向具體指定某一命名空間中的某一Action。而標(biāo)簽的主體用于顯示及渲染Actionr的處理結(jié)果。
    1WebRoot"pages"dataTagssuccess.jsp處理頁(yè)面

    <%@ page contentType="text/html; charset=GBK"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
        
    <head>
            
    <title>Action Tag 示例</title>
        
    </head>
        
    <body>
            
    <h2>
                Action Tag 示例
            
    </h2>
            
    <s:action name="success">
                
    <b><i>s:action標(biāo)簽用于在頁(yè)面顯示結(jié)果.</i></b>
            
    </s:action>
        
    </body>
    </html>

    這里使用<s:action>標(biāo)簽進(jìn)行頁(yè)面跳轉(zhuǎn),并用于顯示處理的結(jié)果。
    2.先來看struts.xml中的配置:

        <action name="actionTag" class="com.sterning.actionTag">
            
    <result name="success">/pages/dataTags/success.jsp</result>
        
    </action>
    3.接著創(chuàng)建actionTag類:代碼如下:
    package com.sterning;
    import com.opensymphony.xwork2.ActionSupport;
    publicclass actionTag 
    extends ActionSupport {
        
    public String execute() throws Exception{
           return SUCCESS;
        

    }

    其實(shí)該類中沒有做任何處理,只是進(jìn)行頁(yè)面跳轉(zhuǎn)而已。
    4.運(yùn)行效果。

    二、<s:bean>標(biāo)簽

    Bean標(biāo)簽,當(dāng)然需要一個(gè)JavaBean。其的屬性值的操作是經(jīng)由Bean標(biāo)簽中的參數(shù)屬性來進(jìn)行賦值。當(dāng)然,它還有一個(gè)id屬性可以進(jìn)行賦值,由于就可以在上下文中使用這個(gè)Bean。請(qǐng)看如下的頁(yè)面:
    1WebRoot"pages"dataTags"beanTag.jsp,代碼如下:

    <%@ page contentType="text/html; charset=GBK"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
        
    <head>
            
    <title>Bean Tag 示例</title>
        
    </head>
        
    <body>
            
    <h2>Bean Tag 示例</h2>
            
    <s:bean name="com.sterning.companyName" id="uid">
                
    <s:param name="name">sterning</s:param>
                
    <s:property value="%{name}" />
                
    <br>
            
    </s:bean>
        
    </body>
    </html>

    可參其關(guān)聯(lián)的JavaBeancom.sterning.companyName,同時(shí)參數(shù)name賦值為sterning
    2.首先創(chuàng)建Action進(jìn)行跳轉(zhuǎn), src"com"sterning"beanTag.java,代碼如下:

    package com.sterning;
    import com.opensymphony.xwork2.ActionSupport;
    public class beanTag extends ActionSupport {
           
    public String execute() throws Exception{
                  
    return SUCCESS;
           }


    }


    然后創(chuàng)建JavaBeansrc"com"sterning"companyName.java,代碼如下:

    package com.sterning;
    public class companyName {
           
    private String name;
           
    public void setName(String name){
                  
    this.name =name ;
           }

           
    public String getName(){
                  
    return name;
           }

    }

    3Struts.xml的配置

    <action name="beanTag" class="com.sterning.beanTag">
        
    <result name="success">/pages/dataTags/beanTag.jsp</result>
    </action>

    4.運(yùn)行效果

    三、<s:date>標(biāo)簽

    Data標(biāo)簽方便在頁(yè)面進(jìn)行格式化的日期輸出。格式有多種可供選擇。同時(shí),還可以通過在properties屬性文件中定義好”struts.date.format”參數(shù)的值,從而自定義格式輸出。

    Date標(biāo)簽包含三個(gè)屬性,可以從下面的代碼中感受一下,分別是:

    l         Name:

    l         Nice

    l         Format

    1WebRoot"pages"dataTags"dateTag.jsp

    <%@ page contentType="text/html; charset=GBK"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
        
    <head>
            
    <title>Date Tag 示例</title>
        
    </head>
        
    <body>
            
    <h2>顯示當(dāng)前的時(shí)間</h2>
            
    <table border="1" width="35%">
                
    <tr>
                    
    <td><b>日期格式</b></td>
                    
    <td><b>日期</b></td>
                
    </tr>
                
    <tr>
                    
    <td>Day/Month/Year</td>
                    
    <td><s:date name="currentDate" format="dd/MM/yyyy" /></td>
                
    </tr>
                
    <tr>
                    
    <td>Month/Day/Year</td>
                    
    <td><s:date name="currentDate" format="MM/dd/yyyy" /></td>
                
    </tr>
                
    <tr>
                    
    <td>Month/Day/Year</td>
                    
    <td><s:date name="currentDate" format="MM/dd/yy" /></td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year Hour
                        
    <B>:</B>Minute
                    
    </td>
                    
    <td><s:date name="currentDate" format="MM/dd/yy hh:mm" /></td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year Hour
                        
    <B>:</B>Minute
                        
    <B>:</B>Second
                    
    </td>
                    
    <td><s:date name="currentDate" format="MM/dd/yy hh:mm:ss" /></td>
                
    </tr>
                
    <tr>
                    
    <td>Nice Date (Current Date & Time)</td>
                    
    <td><s:date name="currentDate" nice="false" /></td>
                
    </tr>
                
    <tr>
                    
    <td>Nice Date</td>
                    
    <td><s:date name="currentDate" nice="true" /></td>
                
    </tr>
            
    </table>
        
    </body>
    </html>


    2src"com"sterning"beanTag.java
    該項(xiàng)類更加簡(jiǎn)單,頁(yè)面跳轉(zhuǎn)

    package com.sterning;
    import com.opensymphony.xwork2.ActionSupport;
    public class beanTag extends ActionSupport {
           
    public String execute() throws Exception{
                  
    return SUCCESS;
           }

    }

    3Struts.xml配置

    <action name="dateTag" class="com.sterning.dateTag">                
          
    <result>/pages/dataTags/dateTag.jsp</result>
    </action>

    4.運(yùn)行效果


    3.<s:date>標(biāo)簽

    四、<s:include>標(biāo)簽
        
    <s:include>標(biāo)簽用于在當(dāng)前頁(yè)面中包含來自其它servletJSP頁(yè)面的處理結(jié)果。由于是頁(yè)面與頁(yè)面(或servlet)之間的頁(yè)面包含,因此不需要action來進(jìn)行頁(yè)面的跳轉(zhuǎn)。
    1WebRoot"pages"dataTags"includeTag.jsp

    <%@ page contentType="text/html; charset=GBK" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
           
    <head>
                  
    <title>Include Tag 示例</title>
           
    </head>
           
    <body>
                  
    <h2>Include Tag 示例</h2>
                         
    <s:include value="myBirthday.jsp" />
           
    </body>
    </html>

    這里包含了另外一個(gè)頁(yè)面myBirthday.jsp,其實(shí)相當(dāng)于在JSP頁(yè)面里包含其它的頁(yè)面。原理一樣的。
    2WebRoot"pages"dataTags"myBirthday.jsp
    這個(gè)頁(yè)面利用了上面所講的<s:date>標(biāo)簽進(jìn)行日期的格式化輸出

    <%@ page contentType="text/html; charset=GBK"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
        
    <head>
            
    <title>Include Tag 示例</title>
        
    </head>
        
    <body>
            
    <table border="1" width="35%">
                
    <tr>
                    
    <td>
                        
    <b>Date Format</b>
                    
    </td>
                    
    <td>
                        
    <b>Date</b>
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Day/Month/Year
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" format="dd/MM/yyyy" />
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" format="MM/dd/yyyy" />
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" format="MM/dd/yy" />
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year Hour
                        
    <B>:</B>Minute
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" format="MM/dd/yy hh:mm" />
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Month/Day/Year Hour
                        
    <B>:</B>Minute
                        
    <B>:</B>Second
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" format="MM/dd/yy hh:mm:ss" />
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td>
                        Nice Date (Current Date & Time)
                    
    </td>
                    
    <td>
                        
    <s:date name="myBirthday" nice="false" />
                    
    </td>
                
    </tr>
            
    </table>
        
    </body>
    </html>

    3Struts.xml配置

    <action name="includeTag" class="com.sterning.includeTag">
         
    <result>/pages/dataTags/includeTag.jsp</result>
    </action>

    4.運(yùn)行效果


    4.<s:include>標(biāo)簽

    五、<s:param>標(biāo)簽

    Param標(biāo)簽用于傳遞參數(shù),如給<s:bean>標(biāo)簽傳遞參數(shù)。它有如下兩個(gè)屬性:

    l         Name(String):參數(shù)名;

    l         Value(Object):參數(shù)值。

    1WebRoot"pages"dataTags"paramTag.jsp

    <%@ page contentType="text/html; charset=GBK" %>

    <%@ taglib prefix="s" uri="/struts-tags" %>

    <html>
           
    <head>
                  
    <title>Param Tag 示例</title>
           
    </head>
           
    <body>
                  
    <h2>Param Tag 示例</h2>
                         
    <ui:component>
                                
    <ui:param name="empname">Emp1</ui:param><br>
                                
    <ui:param name="empname">Emp2</ui:param><br>
                                
    <ui:param name="empname">Emp3</ui:param> 
                         
    </ui:component>
           
    </body>
    </html>


     2Struts.xml配置

                  <action name="paramTag">

                         
    <result>/pages/dataTags/paramTag.jsp</result>

                  
    </action>

    3.運(yùn)行效果


    5.<s:param>標(biāo)簽

    六、<s:set>標(biāo)簽

    Set標(biāo)簽比較簡(jiǎn)單。Set標(biāo)簽用戶將某一值賦給某一變量,因此,任何對(duì)該項(xiàng)值的引用都可以通過該變量來得到該值。該變量的活動(dòng)范圍可自定義。如下例中,定義一健/值對(duì),對(duì)值的引用,直接引用值就可以。。請(qǐng)看示例

    1WebRoot"pages"dataTags" setTag.jsp

    <%@ page contentType="text/html; charset=GBK" %>

    <%@ taglib prefix="s" uri="/struts-tags" %>

    <html>

           
    <head>

                  
    <title>Set Tag 示例</title>

           
    </head>

           
    <body>

                  
    <h2>Set Tag 示例</h2>

                         
    <s:set name="technologyName" value="%{'Java'}"/>

                                Technology Name: 
    <s:property value="#technologyName"/>

           
    </body>

    </html>

    2Struts.xml配置

                  <action name="setTag">

                         
    <result>/pages/dataTags/setTag.jsp</result>

                  
    </action>

    3.運(yùn)行效果


    6.<s:set>標(biāo)簽

    七、<s:property>標(biāo)簽

    Property顧名思義,可以與<s:bean>標(biāo)簽結(jié)合使用,一個(gè)是給bean賦值,一個(gè)是從bean中讀取值。直接來看示例:

    1WebRoot"pages"dataTags"propertyTag.jsp

    <%@ page contentType="text/html; charset=GBK" %>

    <%@ taglib prefix="s" uri="/struts-tags" %>

    <html>

           
    <head>

                  
    <title>Property Tag 示例</title>

           
    </head>

           
    <body>

                  
    <h2>Property Tag 示例</h2>

                         
    <!-- Example to pick the value through bean class -->

                         
    <s:bean name="com.sterning.companyName" id="uid">

                                
    <s:param name="name">sterning</s:param> 

                                       
    <s:property value="%{name}" /><br>

                                
    </s:bean>

                         
    <!-- Default value -->

                                       
    <s:property value="name" default="Default Value" />

           
    </body>

    </html>

    2Bean

    當(dāng)然這里用到了Bean. com"sterning" companyName.java,代碼如下:

    package com.sterning;

    public class companyName {

           
    private String name;

           
    public void setName(String name){

                  
    this.name =name ;

           }


           
    public String getName(){

                  
    return name;

           }


    }

    3src"com"sterning" propertyTag.java

    進(jìn)行頁(yè)面跳轉(zhuǎn)

    package com.sterning;

    import com.opensymphony.xwork2.ActionSupport;

    public class propertyTag extends ActionSupport {

      
    public String execute() throws Exception{

        
    return SUCCESS;

     }


    }

    4Struts.xml配置

                  <action name="propertyTag" class="com.sterning.propertyTag">

                         
    <result>/pages/dataTags/propertyTag.jsp</result>

                  
    </action>

    5.運(yùn)行效果


    7.<s:property>標(biāo)簽

    posted on 2009-02-14 21:07 草原上的駱駝 閱讀(851) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA框架

    主站蜘蛛池模板: 中国一级特黄的片子免费 | 亚洲国产精品美女| 男女一边桶一边摸一边脱视频免费 | 久久久久亚洲AV无码去区首| 精品免费人成视频app| 国产AV无码专区亚洲AV毛网站| 永久免费精品影视网站| 国产成人免费a在线资源| 亚洲高清一区二区三区| 亚洲免费一级视频| 亚洲韩国在线一卡二卡| 国产情侣久久久久aⅴ免费| 中文亚洲成a人片在线观看| 一级特级女人18毛片免费视频| 国产精品酒店视频免费看| 亚洲中文字幕AV每天更新| 国国内清清草原免费视频99| 亚洲精品福利网泷泽萝拉| 午夜老司机永久免费看片| 久久精品国产亚洲香蕉| 国产一区二区免费| 亚洲av伊人久久综合密臀性色| 九九99热免费最新版| 在线观看亚洲天天一三视| 中文字幕永久免费视频| 伊人久久大香线蕉亚洲 | 91在线老王精品免费播放| 久久精品国产亚洲AV麻豆~| 精品亚洲永久免费精品| 亚洲av永久无码精品表情包| 免费看黄的成人APP| 国产V亚洲V天堂无码久久久| 91视频精品全国免费观看| 亚洲永久无码3D动漫一区| a级毛片免费高清毛片视频| 日本亚洲国产一区二区三区| 一区二区三区免费高清视频| 国产精品亚洲不卡一区二区三区| 一本一道dvd在线观看免费视频| 亚洲精品国产成人影院| 国产精品综合专区中文字幕免费播放 |