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

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

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

    愚僧

    贏與輸?shù)牟顒e通常是--不放棄

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      23 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks


    步驟:
    1. 定義tld標(biāo)簽描述文件
    2. 新建class繼承SimpleTagSupport或者BodyTagSupport
    3. taglib命令聲明
    4. 使用自定義標(biāo)簽

    1. 定義tld標(biāo)簽描述文件custom_tag.tld
    <?xml version="1.0" encoding="UTF-8"?>
    <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
        version
    ="2.0">
        <description>JSTL 1.1 core library</description>
        <display-name>JSTL core</display-name>
        <tlib-version>1.1</tlib-version>
        <short-name>ct</short-name>
        <!-- 與 taglib 的 uri 對(duì)應(yīng) -->
        <uri>http://www.customtag.com/custom_tag</uri>
        <!-- 定義一個(gè)標(biāo)簽 -->
        <tag>
            <!-- 標(biāo)簽的名稱 -->
            <name>date</name>
            <!-- 標(biāo)簽類 -->
            <tag-class>com.customtag.tags.DateTag</tag-class>
            <!-- 標(biāo)簽體 -->
            <body-content>empty</body-content>
            <attribute>
                <!-- 屬性名稱 -->
                <name>format</name>
                <!-- 是否必選 true:必選 -->
                <required>false</required>
                <!-- 是否允許使用表達(dá)式(EL), false:不能使用 -->
                <rtexprvalue>false</rtexprvalue>
            </attribute>
            <attribute>
                <name>value</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
        </tag>
    </taglib>
    注:
    可參考jstl-[version].jar中META-INF下的c.tld文件

    2. 新建DateTag繼承SimpleTagSupport或者BodyTagSupport
    package com.customtag.tags;

    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.tagext.SimpleTagSupport;

    public class DateTag extends SimpleTagSupport {
        
        @Override
        public void doTag() throws JspException, IOException {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            PageContext pc = (PageContext) getJspContext();
            JspWriter out = pc.getOut();
            try{
                if(null != this.getValue()){
                    out.print(sdf.format(new Date(this.getValue())));
                }else{
                    out.print(sdf.format(new Date()));
                }
            }catch(IOException e){
                throw e;
            }catch(Exception e){
                out.print("");
            }
        }
        
        private String format="yyyy-MM-dd HH:mm:ss";
        
        private Long value = null;
        
        public String getFormat() {
            return format;
        }

        public void setFormat(String format) {
            this.format = format;
        }

        public Long getValue() {
            return value;
        }

        public void setValue(Long value) {
            this.value = value;
        }
        
    }

    3. taglib命令聲明
    <%@taglib prefix="ct" uri="http://www.customtag.com/custom_tag"%>

    4. 使用自定義標(biāo)簽
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        
    String path = request.getContextPath();
        
    String basePath = request.getScheme() + "://"
                
    + request.getServerName() + ":" + request.getServerPort()
                
    + path + "/";
    %>
    <%@taglib prefix="ct" uri="http://www.customtag.com/custom_tag"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <base href="<%=basePath%>">

            <title>My JSP 'index.jsp' starting page</title>
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
            <link rel="stylesheet" type="text/css" href="styles.css">
            
    -->
        </head>

        <body>
            自定義標(biāo)簽測(cè)試 : 
            <br>
            <ct:date/><br/>
            <ct:date format="MM/dd/yyyy"/><br/>
            <ct:date format="yyyy年MM月dd日 HH時(shí)mm分ss秒" value="<%=new Date().getTime() %>"/><br/>
        </body>
    </html>

    [運(yùn)行結(jié)果]
    自定義標(biāo)簽測(cè)試:
    2013-03-04 16:18:29
    03/04/2013
    2013年03月04日 16時(shí)18分29秒
    posted on 2013-03-04 16:35 ywm 閱讀(119) 評(píng)論(0)  編輯  收藏 所屬分類: servlet & jspstruts

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久福利青草精品资源站免费| 一区二区三区免费在线视频 | 一级特黄aaa大片免费看| 女人张开腿给人桶免费视频| 久久国产亚洲精品| 免费无码黄十八禁网站在线观看| 亚洲综合色丁香麻豆| 88av免费观看入口在线| 亚洲国产人成网站在线电影动漫| 一级毛片在线观看免费| 亚洲视频一区网站| 日本妇人成熟免费中文字幕| 亚洲影视自拍揄拍愉拍| 四虎在线免费播放| 免费人人潮人人爽一区二区| 亚洲第一区精品日韩在线播放| 国产在线观看免费av站| 久久亚洲精品中文字幕无码| 37pao成人国产永久免费视频| 亚洲毛片基地4455ww| 国产福利免费在线观看| 国产久爱免费精品视频| 亚洲AV日韩AV永久无码绿巨人| 1000部啪啪毛片免费看| 亚洲JIZZJIZZ妇女| 一本色道久久综合亚洲精品高清 | 亚洲成人免费电影| 日本久久久免费高清| 中文字幕的电影免费网站| 久久精品亚洲中文字幕无码麻豆| 免费H网站在线观看的| 精品国产亚洲一区二区三区在线观看 | 久久久久免费看黄A片APP| 高h视频在线免费观看| 久久噜噜噜久久亚洲va久| 天天拍拍天天爽免费视频| a级毛片免费观看在线| 亚洲理论片中文字幕电影| 免费a级毛片无码a∨性按摩| 国产精品免费大片| 亚洲人片在线观看天堂无码|