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, it’s a unique name for the tag library the TLD describes. The URI is what you put in your taglib directive. It’s what tells the Container how to identify the TLD file within the web app, which the Container needs in order to map the tag name used in the JSP to the Java code that runs when you use the tag.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset