Java & J2EE Page 9 - Overview of Java Web Technologies, Part 2 |
Writing a Tag Library Descriptor (TLD) A TLD is an XML document that describes a tag library. A TLD is validated against a DTD file. Currently, the latest version of the DTD is 1.2. A TLD must begin with the following header: The root element of a TLD file is <taglib>. The subelements for the taglib element are as follows: A taglib element must have the following elements:
The other subelements are optional. You can read the description of each element in the DTD file downloadable from http://java.sun.com/dtd/web-jsptaglibarary_1_2.dtd. Using a Custom Tag in a JSP Page To use a custom tag in a JSP page, you need to be familiar with the taglib directive in JSP. A taglib directive has the following syntax: The uri attribute specifies an absolute or relative URI that uniquely identifies the TLD associated with this prefix. The prefix attribute defines a string that will become the prefix to distinguish a custom action. With a taglib directive, you can use a custom tag of the following format for a custom tag that does not have a content body: Or, you can use the following format for a custom tag that has a content body: You can pass attributes to the tag handler by specifying the attributes in the custom tag, each with the following format: The following example is a custom tag whose prefix is m and whose name is myTag. The tag has two attributes: number, with a value of 12, and power, with a value of 13. Note that an attribute value must be enclosed in quotation marks.
blog comments powered by Disqus |
|
|
|
|
|
|
|