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

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

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

    176142998

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
    Struts2提供了大量豐富的標(biāo)簽供使用,它不再像Struts1中一樣,將種類(lèi)標(biāo)簽進(jìn)行分門(mén)列別,但可以根據(jù)其使用的用途用以區(qū)別。本文通過(guò)對(duì)Struts2中數(shù)據(jù)標(biāo)簽的學(xué)習(xí),來(lái)對(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)簽,顧名思義,是用來(lái)調(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></div>

                         
    </s:action>

           
    </body>

    </html>

     

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

    2.先來(lái)看struts.xml中的配置:

     

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

               
    <result name="success">/pages/dataTags/success.jsp</result>

           
    </action>

     

    3.接著創(chuàng)建actionTag類(lèi):代碼如下:

     

    package com.sterning;

    import com.opensymphony.xwork2.ActionSupport;

    publicclass actionTag 
    extends ActionSupport {

        
    public String execute() throws Exception{

           returnSUCCESS;

        }


    }

     

    其實(shí)該類(lèi)中沒(méi)有做任何處理,只是進(jìn)行頁(yè)面跳轉(zhuǎn)而已。

    4.運(yùn)行效果。


    1.<s:action>標(biāo)簽

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

    Bean標(biāo)簽,當(dāng)然需要一個(gè)JavaBean。其的屬性值的操作是經(jīng)由Bean標(biāo)簽中的參數(shù)屬性來(lái)進(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的配置

    這里配置很簡(jiǎn)單,與前面的例子差不多。

     

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

                         
    <result name="success">/pages/dataTags/beanTag.jsp</result>

                  
    </action>

     

    4.運(yùn)行效果


    2.<s:bean>標(biāo)簽

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

    Data標(biāo)簽方便在頁(yè)面進(jìn)行格式化的日期輸出。格式有多種可供選擇。同時(shí),還可以通過(guò)在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)類(lèi)更加簡(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è)面中包含來(lái)自其它servletJSP頁(yè)面的處理結(jié)果。由于是頁(yè)面與頁(yè)面(或servlet)之間的頁(yè)面包含,因此不需要action來(lái)進(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)簽用戶(hù)將某一值賦給某一變量,因此,任何對(duì)該項(xiàng)值的引用都可以通過(guò)該變量來(lái)得到該值。該變量的活動(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中讀取值。直接來(lái)看示例:

    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 2008-08-04 10:58 飛飛 閱讀(373) 評(píng)論(1)  編輯  收藏

    Feedback

    # re: Struts2中數(shù)據(jù)標(biāo)簽使用示例 2008-12-12 13:26 tpf
    好,正需要了!
      回復(fù)  更多評(píng)論
      


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 中文字幕成人免费视频| a级毛片视频免费观看| 黄色a级片免费看| 一级毛片免费在线观看网站| 97无码人妻福利免费公开在线视频| 国产精品白浆在线观看免费| 91精品免费国产高清在线| 日本特黄特色aa大片免费| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲国产天堂在线观看| 亚洲人配人种jizz| 日本免费精品一区二区三区| 日本不卡免费新一区二区三区| av大片在线无码免费| 国产乱子伦精品免费无码专区| 亚洲一区AV无码少妇电影☆| 亚洲麻豆精品果冻传媒| 九九精品国产亚洲AV日韩| a级毛片免费在线观看| 免费观看国产网址你懂的| 国产精品视_精品国产免费| 亚洲午夜福利717| 在线观看亚洲AV日韩A∨| 国产视频精品免费视频| 两性刺激生活片免费视频| 亚洲国产精品嫩草影院久久| 亚洲网站视频在线观看| 国产亚洲漂亮白嫩美女在线| 免费人妻无码不卡中文字幕系| 日韩激情淫片免费看| 亚洲短视频男人的影院| jizzjizz亚洲日本少妇| 免费无码VA一区二区三区| 亚洲国产精品成人久久蜜臀| 亚洲国产超清无码专区| yy一级毛片免费视频| 国产香蕉九九久久精品免费| 亚洲色欲久久久综合网| 亚洲人成人无码.www石榴| 成人久久免费网站| 国产成人免费高清在线观看|