A "Hello World" Tag

To create a custom JSP tag, you must first create a Java class that acts as a tag handler. Whenever your custom tag appears in a Java Server Page, the JSP engine invokes your tag handler. If your custom tag doesn't care about the body text between its opening and closing tags, you can use the simple TagSupport class, which implements the Tag interface. If you need to access and possibly change the body text within the opening and closing tags, you must subclass the BodyTagSupport class instead. The BodyTagSupport class implements the BodyTag interface, which allows you to access body text.

For example, suppose you define a custom tag named <mytags:DoSomething> and use it this way:

 <mytags:DoSomething> Here is some text </mytags:DoSomething> ...

Get Special Edition Using Java™ 2 Enterprise 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.