Adding custom JSP tags

You can create custom JSP tags for your web projects that are based on the Oracle JSP 1.2 Specification. Tag libraries enable you to enhance your website regardless of your proficiency in the Java™ programming language.

About this task

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, you must 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 by using 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:

Procedure

  1. Add the TLD file.
  2. Add a taglib directive to the JSP file.
  3. Specify the taglib directive.
  4. Optional: Edit the custom tag properties.
  5. Optional: Edit the web deployment descriptor file for the custom tag library.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: taddcustjsptg.html