[ Team LiB ] Previous Section Next Section

Tag Files—Tag Extensions Without Java

Tag files make it possible for Web developers to create tag handlers without knowing Java. Tag files are created using JSP syntax and produce a tag handler at translation time. Let's jump right in and create our first tag file, as shown in Listing 16.21.

Listing 16.21 Source Code for HelloWorld.tag
Hello World

Remarkably, that's all there is to it. The tag must have an extension of .tag. The source for a JSP that uses HelloWorld.tag is found in Listing 16.22.

Listing 16.22 Source Code for HelloWorld.jsp
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<tags:HelloWorld />

To deploy a tag file, you can place it in one of two locations:

  • In a JAR file installed in the /WEB-INF/lib/ of the Web application. The tag file must be in the META_INF/tags/ directory or a subdirectory of that directory.

  • In the /WEB-INF/tags/ directory (or a subdirectory of that directory) of the Web application.

If you elect to deploy your tag file (as part of an application or library) in a JAR file, you must create a TLD for it. A new element, <tag-file>, describes tags within a tag library. It consists of two subelements, name and path, which define the name of the tag and location of the tag file. <tag-file> is analogous to <tag>, and both can be used within the same tag library.

    [ Team LiB ] Previous Section Next Section