Jsp taglib directive

The taglib directive is used to include a custom tag library so that the JSP can make use of the tags defined in the tag library. There are two types of tags: standard tags and user defined custom tags.

Each self-defined tag must have three components:
  • A tag handler class that specifies the behavior of the new defined tag
  • A Tag Library Descriptor (TLD) XML file with an extension .tld that describes all tags in the tag library.  It maps the tag names to their tag handler classes in the library
  • A JSP page that uses the user defined tag.
The syntax of taglib directive is:

<%@ taglib uri=”<taglib.tld>” prefix=”<p_name>”   %>

where the Uniform Resource Identifier(URI) attribute specifies the absolute or relative URI to the TLD file. 

For example, you can use a custom tag in this way: 

<p_name:myTag> . . . </p_name:myTag> 

where myTag is defined in taglib.tld with the prefix p_name.