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:
- Create a tag library definition file (*.tld) that contains the definition, or grammar, of the new tag or tags.
- Write classes to contain the functionality of the tag.
- 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
- 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.
- Write Java classes that extend the TagSupport class to implement the function for the tag.
- Compile the Java files.
- Write one or more JSP files that use the new tags.
- Assemble the application that includes your JSP files. Add the TLD file as a resource file by performing the following steps:
- Start the application assembly tool.
- In the navigation pane, click the Files icon to expand the directory structure.
- Right-click the Resource Files folder and select Add Files.
- Browse for the archive file (JAR, WAR, EAR, or ZIP file) that contains the TLD, and then click it to select it.
- Click Add, and then click OK.
- In the navigation pane under the Web module, right-click the Tag Libraries icon and select New.
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.
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:
- In the navigation pane, click the Files icon to expand the directory structure.
- Right-click the Resource Files folder and select Add Files.
- Browse for the archive file (JAR, WAR, EAR, or ZIP file) that contains the .class files, then click it to select it.
- Click Add, and then click OK.