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

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

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

    HelloWorld 善戰者,求之于勢,不責于人;故能擇人而任勢。

    知止而后有定,定而后能靜,靜而后能安,安而后能慮,慮而后能得。物有本末,事有終始。知所先后,則近道矣。

      BlogJava :: 首頁 ::  :: 聯系 ::  :: 管理 ::
      167 隨筆 :: 1 文章 :: 40 評論 :: 0 Trackbacks

     

    義最簡單的標簽   
    自定義標簽采用Default Adapter模式(缺省適配模式) 

    Java代碼

    Java代碼 

    //最簡單的標簽       

    public class LangHuaTag extends TagSupport {        

        private long startTime;        

        private long endTime;        

                

        public int doStartTag() throws JspException {        

            startTime = System.currentTimeMillis();        

            //表示定制標記里面有所包括的JSP頁面       

            return TagSupport.EVAL_BODY_INCLUDE;        

    10     }        

    11     public int doEndTag() throws JspException {        

    12         endTime = System.currentTimeMillis();        

    13         long elapsed = endTime - startTime;             

    14         try {        

    15             JspWriter out = pageContext.getOut();        

    16             out.println("runtime is "+ elapsed);        

    17         } catch (IOException e) {        

    18             e.printStackTrace();        

    19         }        

    20         //表示JSP頁面繼續運行       

    21         return TagSupport.EVAL_PAGE;        

    22     }        

    23             

    24 }        

    25 //代屬性的標簽       

    26 public class DateTag extends TagSupport {        

    27     private String pattern = "yyyy-MM-dd hh:mm:ss";        

    28     private Date date;        

    29     //必須要有Set方法,因為是屬性可以設值       

    30     public void setPattern(String pattern) {        

    31         this.pattern = pattern;        

    32     }        

    33             

    34     public void setDate(Date date) {        

    35         this.date = date;        

    36     }        

    37        

    38     public int doEndTag() throws JspException {        

    39         SimpleDateFormat sdf = new SimpleDateFormat(pattern);        

    40         //如果沒有就是當前時間       

    41         if(date==null){        

    42             date = new Date();        

    43         }               

    44         JspWriter out = pageContext.getOut();        

    45         try {        

    46             out.print(sdf.format(date));        

    47         } catch (IOException e) {        

    48             e.printStackTrace();        

    49         }        

    50         return TagSupport.EVAL_PAGE;        

    51     }        

    52 }        

    53        

    54 /**    

    55  * 循環輸出    

    56  * @author Administrator    

    57  *    

    58  */       

    59 public class LoopTag extends TagSupport {        

    60     private int times =0;        

    61     //Set方法設值       

    62     public void setTimes(int times) {        

    63         this.times = times;        

    64     }        

    65             

    66     public int doStartTag() throws JspException {        

    67         //表示定制標記里面有所包括的JSP頁面       

    68         return TagSupport.EVAL_BODY_INCLUDE;        

    69     }        

    70             

    71     public int doAfterBody() throws JspException {        

    72         if(times>0){        

    73             times--;        

    74             //表示雙從標簽開始輸入       

    75             return TagSupport.EVAL_BODY_AGAIN;        

    76         }           

    77         //表示結束,忽略標簽內部的內容       

    78         return TagSupport.SKIP_BODY;        

    79     }        

    80             

    81 }      

    配置文件   
    Xml代碼

    Xml代碼 

    82 <?xml version="1.0" encoding="UTF-8" ?>       

    83 <taglib xmlns="http://java.sun.com/xml/ns/j2ee"       

    84     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       

    85     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"       

    86     version="2.0">       

    87     <tlib-version>1.0</tlib-version>       

    88     <short-name>util</short-name>       

    89     <uri>http://langhua.com/taglib/util</uri>       

    90     <tag>       

    91         <name>timer</name>       

    92         <tag-class>com.langhua.tagsupport.LangHuaTag</tag-class>       

    93         <body-content>JSP</body-content>       

    94         <!-- JSP,empty表示能能包函內容的,scriptless,tagdependent -->       

    95     </tag>       

    96             

    97     <tag>       

    98         <name>date</name>       

    99         <tag-class>com.langhua.tagsupport.DateTag</tag-class>       

    100         <body-content>empty</body-content>              

    101         <!-- JSP,empty表示不能包函內容的,scriptless,tagdependent -->       

    102         <attribute>       

    103             <!-- 標簽名 -->       

    104             <name>time</name>       

    105             <!-- 是否為可選屬性 -->       

    106             <required>false</required>       

    107             <!-- 是否接受JSP表達示計算結果 -->       

    108             <rtexprvalue>true</rtexprvalue>       

    109         </attribute>       

    110         <attribute>       

    111             <name>pattern</name>       

    112             <required>true</required>       

    113             <rtexprvalue>false</rtexprvalue>       

    114         </attribute>       

    115     </tag>       

    116             

    117     <tag>       

    118         <name>loop</name>       

    119         <tag-class>com.langhua.tagsupport.LoopTag</tag-class>       

    120         <body-content>JSP</body-content>                

    121         <!-- JSP,empty表示不能包函內容的,scriptless,tagdependent -->       

    122         <attribute>       

    123             <!-- 標簽名 -->       

    124             <name>times</name>       

    125             <!-- 是否為可選屬性 -->       

    126             <required>true</required>       

    127             <!-- 是否接受JSP表達示計算結果 -->       

    128             <rtexprvalue>true</rtexprvalue>       

    129         </attribute>              

    130     </tag>       

    131 </taglib>      

     

    JSP頁面   
    Html代碼  

    Html代碼 

    132 <%@ taglib prefix="util" uri="http://langhua.com/taglib/util"%>       

    133        

    134 <util:timer></util:timer>       

    135 <util:loop times="3">       

    136     <util:date pattern="yyyy-MM-dd" /><br/>       

    137 </util:loop>       

    138      

    139 <%@ taglib prefix="util" uri="http://langhua.com/taglib/util"%>     

    140      

    141 <util:timer></util:timer>     

    142 <util:loop times="3">     

    143     <util:date pattern="yyyy-MM-dd" /><br/>     

    144 </util:loop>  

     

    TagSupport的流程圖

          SKIP_BODY 表示不用處理標簽體,直接調用doEndTag()方法。
      
        SKIP_PAGE 忽略標簽后面的JSP內容。
      
      EVAL_PAGE 處理標簽后,繼續處理JSP后面的內容。
      
      EVAL_BODY_BUFFERED 表示需要處理標簽體。
      
      EVAL_BODY_INCLUDE 表示需要處理標簽體,但繞過setBodyContent()doInitBody()方法
      
      EVAL_BODY_AGAIN 對標簽體循環處理。



    </script>

    posted on 2010-09-16 13:55 helloworld2008 閱讀(1495) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲黄色免费网址| 日本不卡免费新一区二区三区| 亚洲天天做日日做天天欢毛片| 亚洲国产精品不卡毛片a在线| 亚洲性线免费观看视频成熟 | 国产又粗又长又硬免费视频| 日本xxxx色视频在线观看免费| 一级毛片在线播放免费| 亚洲av成人一区二区三区在线播放 | 亚洲国产精品无码中文字| 免费在线视频一区| 女人毛片a级大学毛片免费| 人与禽交免费网站视频| 99久久综合精品免费 | 色婷婷亚洲十月十月色天| 亚洲日韩中文无码久久| 区三区激情福利综合中文字幕在线一区亚洲视频1| 成人免费激情视频| 永久免费在线观看视频| 91精品免费高清在线| 久久久久久久久久国产精品免费 | 日韩精品成人亚洲专区| 国产成人在线观看免费网站| 精品久久免费视频| 在线jyzzjyzz免费视频| 免费观看黄网站在线播放| 91在线视频免费播放| 亚洲精品免费网站| 久久天天躁狠狠躁夜夜免费观看| 5g影院5g天天爽永久免费影院| 久久aa毛片免费播放嗯啊| 免费视频精品一区二区三区 | 亚洲欧洲日产国产综合网| 亚洲韩国—中文字幕| 亚洲今日精彩视频| 亚洲一区二区影院| 亚洲成人黄色在线观看| 亚洲剧情在线观看| 亚洲中文无码永久免| 老司机亚洲精品影院在线观看| 精品成人一区二区三区免费视频|