文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Creating and Using a Tag File

Creating and Using a Tag File

时间:2008-09-02  来源:zyme007

A tag file is a text file that contains JSP elements implemented the functionality of a custom action.You must use a .tag filename extension to identify this type of file to the web container.

Example(copyright.tag)
   <%@ tag body-content="empty" %>
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   <jsp:useBean id="now" scope="application" class="java.util.Date" />
   Copyright &copy; ${now.year + 1900} My Company

In most cases,tag file authors only care about the attribute "boby-content".This attribute defines how the custom action element's body should be handled,and that it must have one of these values:empty,scriptless(the default),or tagdependent.If it's empty,trying to use a body for the custom element results in a syntax error.The scriptless value means that the body can contain any JSP elements except the type of scripting elements.If the body-content attribute is set to tagdependent,the action element body is treated as pure template text(i.e.,action elements and EL expression in the boby are not processed,just handled as plain text)
Tag files can be placed directly it the web application structure under the WEB-INF/tags directory or a subdirectory.Each directory containing tag files represents a seperate tag library
    WEB-INF/tags/
      mytags/
        copyright.tag
        forEvenAndOdd.tag
        htmlFormat.tag
        motd.tag
      myothertags/
        foo.tag
        bar.tag

Here we have two tag libraries:mytags and myothertags.By default,the name of the custom action implemented by the tag file is the filename minus the .tag extension,so the copyright.tag file represents a custom action named copyright in the mytags library.

A JSP page must declare that it uses a tag library represented by tag files in the web application structure with a slightly different taglib directive.

    <%@ page contentType="text/html" %>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags/mytags" %>
   
    <html>
      <body bgcolor="white">
        ...
        <my:copyright/>
      </body>
    </html>

NOTE that the tagdir attribute is used instead of the uri attribute.The value of the tagdir attribute is the context-relative path to the directory that contains the tag files for the library.

Tag files can also be packaged in a JAR file.One thing to note at this time,though,is that when the tag files are packaged in a JAR file,the taglib directive is used with the 'uri' attribute exactly.
相关阅读 更多 +
排行榜 更多 +
百炼英雄抽卡技巧指南

百炼英雄抽卡技巧指南

休闲益智 下载
英雄没有闪滚雷旋风技能如何搭配

英雄没有闪滚雷旋风技能如何搭配

休闲益智 下载
英雄没有闪雷旋风BD构筑推荐

英雄没有闪雷旋风BD构筑推荐

休闲益智 下载