[ Team LiB ] Previous Section Next Section

Recipe 22.12 Packaging the JSP Tag File in a Web Application


You want to store the tag file for use in a web application.


Place the tag file in WEB-INF/tags or in META-INF/tags inside a JAR file or in a subdirectory of either of these directories. If you do this you do not need to describe the tag in a TLD file.


The JSP container finds the tag file by using the tagDir attribute of the taglib directive. In other words, the tagDir attribute provides the path to the web application directory where you stored the tag file. Here's an example:

<%@ taglib prefix="cbck" tagdir="/WEB-INF/tags" %>

As long as you place the tag file, which has a .tag extension (or .tagx extension if the tag file is in XML syntax) in /WEB-INF/tags, JSPs can to use the tag associated with the tag file.

The JSP has to position the taglib directive in the code before the JSP uses the associated custom tag.

The JSP 2.0 TLD can also specify the tag file in the following manner:


This TLD entry specifies a tag file named dbSelect.tag, which resides in the /WEB-INF/tags/dbtags directory. The path attribute must begin with "/META-INF/tags" if the tag file resides in a JAR, and "/WEB-INF/tags" if the tag file is located in a Web Archive (WAR) file or in a nonarchived web application.

See Also

The JSP 2.0 specification web page: http://jcp.org/en/jsr/detail?id=152; Recipe 22.2 and Recipe 22.3 on creating TLD files for tag libraries; Recipe 22.4 and Recipe 22.5 on packaging a tag library in a web application; Recipe 22.6 on using the custom tag in a JSP; Recipe 22.7 on handling exceptions in tags; Recipe 22.8 and Recipe 22.9 on creating a simple tag handler; Recipe 22.10 on using the simple tag handler in a JSP; Recipe 22.13 and Recipe 22.14 on packaging a tag file and using it in a JSP; Recipe 22.15 on adding a listener class to a tag library; the custom tag sections of Hans Bergsten's JavaServer Pages, Third Edition (O'Reilly).

    [ Team LiB ] Previous Section Next Section