In JSP it is possible to define your own custom HTML tags. This topic describes the specifics of creating a custom tag within WebLogic Workshop. However, it does not discuss custom tag creation itself. For detailed information on creating custom JSP tags, see your favorite JSP documentation. To examine a sample that uses custom tags, see CustomTags.jsp Sample.
To write a custom tag, you must:
If you have a set of custom tags that you want to use in multiple applications, you might want to build a JAR library.
Location of the Tag Handler File
The tag handler class contains the Java code that is executed whenever the JSP engine encounters your custom tag on a JSP page. The tag handler class extends javax.servlet.jsp.tagext.TagSupport, and contains variables and methods that handle the various parts of an HTML tag, such as doStartTag and doEndTag.
In WebLogic Workshop, the tag handler file must be located in WEB-INF/src. For example, in the sample mentioned above, various tag handler files are located in WEB-INF/src/tag_handlers.
Location of the Tag Library Descriptor File
The tag library descriptor (TLD) file tells the JSP processor where to find the tag handler class. A JSP page that uses these custom actions references this file, as in this example:
<%@taglib prefix="custom" uri="/WEB-INF/taglib.tld"%>
As the example shows, the TLD file should be located in the WEB-INF folder.
Editing the file web.xml
When you edit the web.xml file and define the tag library descriptor file, the custom tags will appear in the Palette window when you are working with a JSP in your web project. In the file web.xml, locate the definition of the three standard NetUI tag library TLD files, and define your custom tag library descriptor immediately after it. An example of this definition is show in the following example:
<taglib>
<taglib-uri>taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
If you now open a JSP and scroll to the bottom of the Palette window, you will notice the header CustomLibrary (taglib.tld) followed by the custom tags you defined.
Creating a custom tag JAR
To create a JAR library containing custom tags, you should package the tag handle files and the tag library descriptor file in a Java project. For general information on re-using Java code in a Java project, see How Do I: Reuse Existing Java Code?
<%@taglib prefix="custom"
uri="/WEB-INF/lib/mytags.jar"%>
<taglib>
<taglib-uri>taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/lib/mytags.jar</taglib-location>
</taglib>
How Do I: Reuse Existing Java Code?