Chinaunix首页 | 论坛 | 博客
  • 博客访问: 522395
  • 博文数量: 151
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1405
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 14:32
文章分类

全部博文(151)

文章存档

2011年(1)

2010年(23)

2009年(1)

2008年(126)

我的朋友

分类: 系统运维

2008-09-02 11:46:11

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="" %>
  
   Copyright © ${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" %>
   
   
     
        ...
       
     
   

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.
阅读(597) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~