国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

在JSP中編寫你的第一個Tag

2024-09-05 00:20:40
字體:
供稿:網(wǎng)友
  • 本文來源于網(wǎng)頁設計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  •   tag 編寫一個tag涉及三個步驟,

      (1)編寫jsp

      (2)編寫tag的java程序

      (3)編寫tag庫的描述文件tld(實際是一個xml文件)

      這三個步驟之間沒有順序約束,下面是一個簡單的例子:

      1 編寫hellotag.jsp

    <%@page contenttype="text/html"%>
    <html>
    <head><title>hello tags page</title></head>
    <body>
    <%@ taglib uri="/web-inf/classes/tags/hellotag.tld" prefix="hello" %>
    <hello:hellotag />
    </body>
    </html>

      2 編寫tag

      hellotag.java

    package tags; //注意:必須放在一個包中
    import java.io.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class hellotag extends tagsupport {
    public int dostarttag() {
    try {
    //使用jspwriter獲得jsp的輸出對象
    jspwriter jspwriteroutput = pagecontext.getout();
    jspwriteroutput.print("hello tag!");
    } catch (ioexception ioex) {
    system .out.println("ioexception in hellotag " + ioex);
    }
    return (skip_body);
    }
    }

      3 編寫hellotag.tld

      這是tag庫的描述部分:

    <?xml version="1.0" encoding="utf-8" ?>
    <!doctype taglib
    public "-//sun microsystems, inc.//dtd jsp tag library 1.2//en"
    "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <shorttag -name>hellotag</short -name>
    <uri>/web-inftagshellotag</uri>
    <display-name>hellotag</display-name>
    <small-icon></small-icon>
    <large-icon></large-icon>
    <description>simple hello tags tag
    </description>
    <tag>
    <name>hellotag</name>
    <tag-class >tags.hellotag</tag-class >
    <body-content>empty</body-content>
    <small-icon></small-icon>
    <large-icon></large-icon>
    <description></description>
    <example></example>
    </tag>
    </taglib>

      4 注意:

      通常手工編寫xml文件,但是sun的教程建議使用ide工具編寫自定義tag,比如netbeans

      一般,直接把tld文件放到web-inf目錄中。

    發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 乌拉特中旗| 广河县| 罗源县| 宁乡县| 武川县| 高平市| 周宁县| 北票市| 溆浦县| 嵊州市| 湟中县| 永济市| 望江县| 溧水县| 福州市| 南宁市| 桐柏县| 木兰县| 阿拉善盟| 和龙市| 五大连池市| 鹤庆县| 英山县| 南江县| 中卫市| 涡阳县| 湟源县| 天津市| 永昌县| 漳浦县| 尉氏县| 六安市| 盘山县| 兴国县| 大兴区| 南岸区| 南岸区| 金昌市| 师宗县| 璧山县| 平武县|