The Java EE 5 Tutorial

Declaring Tag Files

Although not required for tag files, providing a TLD allows you to share the tag across more than one tag library and lets you import the tag library using a URI instead of the tagdir attribute.

tag-file TLD Element

A tag file is declared in the TLD using a tag-file element. Its subelements are listed in Table 8–8.

Table 8–8 tag-file Subelements




(optional) A description of the tag. 


(optional) Name intended to be displayed by tools. 


(optional) Icon that can be used by tools. 


The unique tag name. 


Where to find the tag file implementing this tag, relative to the root of the web application or the root of the JAR file for a tag library packaged in a JAR. This must begin with /WEB-INF/tags/ if the tag file resides in the WAR, or /META-INF/tags/ if the tag file resides in a JAR.


(optional) Informal description of an example use of the tag. 


(optional) Extensions that provide extra information about the tag for tools. 

Unpackaged Tag Files

Tag files placed in a subdirectory of /WEB-INF/tags/ do not require a TLD file and don’t have to be packaged. Thus, to create reusable JSP code, you simply create a new tag file and place the code inside it.

The web container generates an implicit tag library for each directory under and including /WEB-INF/tags/. There are no special relationships between subdirectories; they are allowed simply for organizational purposes. For example, the following web application contains three tag libraries:


The implicit TLD for each library has the following values:

So, for the example, the implicit TLD for the /WEB-INF/tags/bar/baz/ directory would be as follows:


Despite the existence of an implicit tag library, a TLD in the web application can still create additional tags from the same tag files. To accomplish this, you add a tag-file element with a path that points to the tag file.

Packaged Tag Files



