Using a tag library that’s NOT from the JSTL

Creating the code that goes behind a tag (in other words, the Java code that’s invoked when you put the tag in your JSP) isn’t trivial. We have a whole chapter (the next one) devoted to developing your own custom tag handlers. But the last part of this chapter is about how to use custom tags. What happens, for example, if someone hands you a custom tag library they created for your company or project? How do you know what the tags are and how to use them? With JSTL, it’s easy—the JSTL 1.1 specification documents each tag, including how to use each of the required and optional attributes.

But not every custom tag will come so nicely packaged and well-documented. You have to know how to figure out a tag even if the documentation is weak or nonexistent, and, one more thing—you have to know how to deploy a custom tag library.

Note

To use a custom library, you MUST read the TLD.

Everything you need to know is in there.

Main things you have to know:

  1. The tag name and syntax

    The tag has a name, obviously. In <c:set>, the tag name is set, and the prefix is c. You can use any prefix you want, but the name comes from the TLD. The syntax includes things like required and optional attributes, whether the tag can have a body (and if so, what you can put there), the type of each attribute, and whether the attribute can be an expression (vs. a literal String).

  2. The library URI

    The URI is a unique identifier in the Tag Library Descriptor (TLD). In other words, ...

Get Head First Servlets and JSP, 2nd 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.