j2ee: Tag Files [18/27] ![]() ![]() ![]() |
JSP Tag files are a new addition to the JSP 2.0 specification. They allow JSP authors to create tag extensions that are made only of JSP syntax , instead of Java syntax.
The syntax of a tag file is similar to that of a JSP page, with the following exceptions:
The basic goal it so make it as easy to write a tag file as it is to write a JSP.
Tag files are deployed in the META-INF/tags directory of a jar file in WEB-INF/lib of a
war file, or they are placed in the WEB-INF/tags directory of the web application.
If the former is chosen, the tag library descriptor (.tld) file needs to point
out the details on the tag. If placed in the WEB-INF/tags directory, the tag files
can be discovered by the container, and the container creates the tld. For example,
with a tag file /WEB-INF/tags/depaul/j2ee/demo.tag
, the following tld
would be created:
<taglib> <tlib-version>1.0</tlib-version> <short-name>bar-baz</short-name> <tag-file> <name>demo</name> <path>/WEB-INF/tags/depaul/j2ee/demo.tag</path> </tag-file> </taglib>
In a tag file, the tag directive is used to define the tag itself. All the attributes are optional, but it allows some refinement of the tag behavior
The attribute directive defines the attributes of the tag, just like the attributes of a classic tag. The type and name are defined - along with other options.
The variable directive allows scripting variables to be created and exposed to the calling page, just like classic tags.
Tag files are not in widespread use yet, mainly because the 2.0 spec is not in commercial servers yet. But as you can see, it is a lot easier to create tags this way, and for many application developers, this may become a quick way to break the views up into smaller reusable components.