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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.