Adding custom JSP tags
You can create custom JSP tags for your Web projects based on the Sun Microsystems JSP 1.2 Specification.Tag libraries are usually created by developers who are proficient in the Java programming language and can be used by Web designers who might not know Java, but would like to enhance their Web site by taking advantage of Java encoded tag libraries.
Implementing custom tags requires all of the following:
- Defining custom tags in a Tag Library Descriptor (TLD) file. This is analogous to defining XML tags in a DTD file. The TLD file is an XML file that describes the custom tags in a tag library and includes tag information, such as the tag names, type of content, attributes, and associated tag handler class.
- Using custom tags within a JSP page. To use a custom tag within a JSP page, first identify where the TLD file is located and identify a prefix to be used when any of the custom tags in the library are included in a JSP page. This is accomplished through the use of a taglib directive.
- Creating a Tag Handler class. This is a Java class that implements the Tag or BodyTag interface and is responsible for the implementation of a custom tag at runtime.
A TLD file can be packaged within a JAR file, or as a separately existing project file. If the TLD file is packaged in a JAR file, it must be included under the META-INF folder.
You can add your custom tag library and tag library descriptor files to your project as you would any other project file.
To add custom JSP tags, you typically follow this process:
- Adding the Tag Library Descriptor (TLD) file.
- Adding a taglib directive to a JSP file.
- Specifying the taglib directive.
- Adding a custom tag to a JSP file.
- Editing the properties of a custom tag (optional).
- Editing a Web deployment descriptor file for a custom tag library (optional).
Related concepts
Custom tag libraries
Related tasks
Adding the Tag Library Descriptor (TLD) file
Adding a taglib directive to a JSP file
Specifying the taglib directive
Adding a custom tag to a JSP file
Editing the properties of a custom tag
Editing a Web deployment descriptor file for a custom tag library
Related reference
Tag libraries