JSP tag extensions support

Use custom JSP tags to assist in replacing functionality currently implemented with a scriptlet (inline Java code). Encapsulating this functionality with a custom JSP tag allows you to more cleanly separate business logic from the presentation of the HTML output that displays in the user's browser.

The basic steps for using JSP tag extensions are:

  1. Create a tag library definition file (*.tld) that contains the definition, or grammar, of the new tag or tags.
  2. Write classes to contain the functionality of the tag.
  3. Write or change the JSP code to use the new tag and specify the tag library.

For more information about Tag Extensions and Tag Libraries see the Custom Tags in JSP Pages Link outside Information Center

  1. Create the tag library definition. This XML file defines the list of tags, the Java class that implements the tags, and the names that the JSP file uses to refer to those tags.
  2. Write Java classes that extend the TagSupport class to implement the function for the tag.
  3. Compile the Java files.
  4. Write one or more JSP files that use the new tags.
  5. Assemble the application that includes your JSP files. Add the TLD file as a resource file by performing the following steps:
    1. Start the application assembly tool.
    2. In the navigation pane, click the Files icon to expand the directory structure.
    3. Right-click the Resource Files folder and select Add Files.
    4. Browse for the archive file (JAR, WAR, EAR, or ZIP file) that contains the TLD, and then click it to select it.
    5. Click Add, and then click OK.
    6. In the navigation pane under the Web module, right-click the Tag Libraries icon and select New.
    7. Provide the following properties for the TLD:

      • Tag library file name
        This field identifies the tag library descriptor to the Web module. Use the value of this field in your JSPs when referring to the tag library descriptor.

      • Tag library location
        This is the location of the tag library descriptor file in the file system. Note that specify the location relative to the root of the Web module.

  6. Place the Java classes that you wrote in the servlet classpath of the Web module in which the JSP files are deployed. This is done so that the JSP processor can find the code to implement the new tags. The class files must be located in the WEB-INF/classes directory.

    Alternatively, you can add them to the Web module using the following steps:

    1. In the navigation pane, click the Files icon to expand the directory structure.
    2. Right-click the Resource Files folder and select Add Files.
    3. Browse for the archive file (JAR, WAR, EAR, or ZIP file) that contains the .class files, then click it to select it.
    4. Click Add, and then click OK.