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

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

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

    176142998

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
    Struts2提供了大量豐富的標簽供使用,它不再像Struts1中一樣,將種類標簽進行分門列別,但可以根據其使用的用途用以區別。本文通過對Struts2中數據標簽的學習,來對Struts2中標簽的學習起到一個拋磚引玉的作用。文中將介紹Action標簽、Bean標簽、Data標簽、Include標簽、Param標簽、Set標簽、Text標簽、Property標簽等標簽。
    一、<s:action>標簽

    Action標簽,顧名思義,是用來調用Action的標簽,在JSP中頁面中,可以指向具體指定某一命名空間中的某一Action。而標簽的主體用于顯示及渲染Actionr的處理結果。

    1WebRoot\pages\dataTagssuccess.jsp處理頁面

     

    <%@ 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標簽用于在頁面顯示結果.</i></b></div>

                         
    </s:action>

           
    </body>

    </html>

     

    這里使用<s:action>標簽進行頁面跳轉,并用于顯示處理的結果。

    2.先來看struts.xml中的配置:

     

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

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

           
    </action>

     

    3.接著創建actionTag類:代碼如下:

     

    package com.sterning;

    import com.opensymphony.xwork2.ActionSupport;

    publicclass actionTag 
    extends ActionSupport {

        
    public String execute() throws Exception{

           returnSUCCESS;

        }


    }

     

    其實該類中沒有做任何處理,只是進行頁面跳轉而已。

    4.運行效果。


    1.<s:action>標簽

    二、<s:bean>標簽

    Bean標簽,當然需要一個JavaBean。其的屬性值的操作是經由Bean標簽中的參數屬性來進行賦值。當然,它還有一個id屬性可以進行賦值,由于就可以在上下文中使用這個Bean。請看如下的頁面:

    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>

     

    可參其關聯的JavaBeancom.sterning.companyName,同時參數name賦值為sterning

    2.首先創建Action進行跳轉, 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;

           }


    }

     

    然后創建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.運行效果


    2.<s:bean>標簽

    三、<s:date>標簽

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

    Date標簽包含三個屬性,可以從下面的代碼中感受一下,分別是:

    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>顯示當前的時間</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

    該項類更加簡單,頁面跳轉

     

    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.運行效果


    3.<s:date>標簽

    四、<s:include>標簽

    <s:include>標簽用于在當前頁面中包含來自其它servletJSP頁面的處理結果。由于是頁面與頁面(或servlet)之間的頁面包含,因此不需要action來進行頁面的跳轉。

    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>

     

    這里包含了另外一個頁面myBirthday.jsp,其實相當于在JSP頁面里包含其它的頁面。原理一樣的。

    2WebRoot\pages\dataTags\myBirthday.jsp

    這個頁面利用了上面所講的<s:date>標簽進行日期的格式化輸出

     

    <%@ 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.運行效果


    4.<s:include>標簽

    五、<s:param>標簽

    Param標簽用于傳遞參數,如給<s:bean>標簽傳遞參數。它有如下兩個屬性:

    l         Name(String):參數名;

    l         Value(Object):參數值。

    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.運行效果


    5.<s:param>標簽

    六、<s:set>標簽

    Set標簽比較簡單。Set標簽用戶將某一值賦給某一變量,因此,任何對該項值的引用都可以通過該變量來得到該值。該變量的活動范圍可自定義。如下例中,定義一健/值對,對值的引用,直接引用值就可以。。請看示例

    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.運行效果


    6.<s:set>標簽

    七、<s:property>標簽

    Property顧名思義,可以與<s:bean>標簽結合使用,一個是給bean賦值,一個是從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

    當然這里用到了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

    進行頁面跳轉

     

    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.運行效果


    7.<s:property>標簽

    posted on 2008-08-04 10:58 飛飛 閱讀(373) 評論(1)  編輯  收藏

    Feedback

    # re: Struts2中數據標簽使用示例 2008-12-12 13:26 tpf
    好,正需要了!
      回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 美女扒开尿口给男人爽免费视频| 在线观看免费高清视频| 麻豆亚洲AV成人无码久久精品| 亚洲AV永久纯肉无码精品动漫 | 久久夜色精品国产噜噜噜亚洲AV| 免费日本黄色网址| 久久WWW色情成人免费观看| 久99久精品免费视频热77| 丝袜足液精子免费视频| 日韩免费在线中文字幕| 亚洲av无码一区二区三区在线播放 | 亚洲理论精品午夜电影| 久久久久久久综合日本亚洲| 亚洲成a人片在线观看日本麻豆| 在线播放免费播放av片| 91在线视频免费91| 亚洲三级在线免费观看| 99久久99久久精品免费观看| 男人的天堂网免费网站| a级毛片免费观看视频| 精品国产免费一区二区三区| 一级做α爱过程免费视频| 免费人成动漫在线播放r18| 国产亚洲综合精品一区二区三区| 亚洲精品一卡2卡3卡四卡乱码| 亚洲AV无码久久久久网站蜜桃| 亚洲国产美女福利直播秀一区二区| 麻豆亚洲AV永久无码精品久久| 亚洲成熟xxxxx电影| 亚洲综合久久综合激情久久| 亚洲AV无一区二区三区久久| 亚洲国产精品va在线播放| 亚洲av永久无码精品漫画 | 中文字幕成人免费高清在线 | 亚洲性久久久影院| 国产午夜亚洲精品午夜鲁丝片| 亚洲亚洲人成综合网络| 久久亚洲国产成人亚| 99ri精品国产亚洲| 亚洲精品国产福利在线观看| 亚洲砖码砖专无区2023|