[ Team LiB ] Previous Section Next Section

Recipe 22.4 Packaging a Tag Library in a Web Application

Problem

You want to make your tag library available in a web application.

Solution

Place your TLD file in WEB-INF or a WEB-INF subdirectory (with the exception of WEB-INF/lib and WEB-INF/classes). Place the tag handler class or classes in WEB-INF/classes.

Discussion

Packaging your tag library outside of a JAR file is typically a two-step process:

  1. Store the TLD file in the WEB-INF directory or a WEB-INF subdirectory, and a JSP container (compliant with Versions 1.2 and 2.0) automatically configures your tag library. The TLD file must have a .tld extension. For example, if you store a mytags.tld in WEB-INF/tlds, then the JSP container automatically finds your TLD file and configure your tag library.

The JSP 2.0 specification states that TLDs should not be placed in WEB-INF/lib or WEB-INF/classes. The JSP container will not look for the TLDs in these locations.


  1. Make sure the tag handler classes for your tag library have a package name (such as com.jspservletcookbook) and are stored in WEB-INF/classes or in a JAR file in WEB-INF/lib.

The next recipe shows how to package your tag library, including the TLD, in a JAR file.

See Also

The XML schema file for the JSP 2.0 TLD: http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd; Recipe 22.2 and Recipe 22.3 on creating TLD files for tag libraries; Recipe 22.5 on packaging tag libraries in a JAR file; 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.11-Recipe 22.14 on using a JSP tag file; 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