Developing a Simple Custom Tag

Unfortunately, using JSTL will not always provide the functionality you need; even when it can, there are circumstances when using your own custom tag might make the JSP simpler to maintain.

A custom tag is made up of two components:

  • A Java class file that implements the tag

  • An entry in a Tag Library Descriptor (TLD) file that defines the tag's name, its implementing Java class, and additional information necessary to deploy and use the tag

Just as with JSTL, using a custom tag requires a reference to the Tag Library Descriptor (TLD) at the start of the JSP. Multiple Tag Libraries can be used on the same Web page. After the TLD has been referenced, the custom tag from the TLD can be used like any other JSP tag.

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.