JSP tags have the same format as HTML tags, which can be used instead of Java scripts in JSPs to introduce code. Before using a custom label, you need to create a *.tld file, each with a tag library that can contain a lot of custom tags.
Each tag must be implemented by an implementation class that inherits the Simpletagsupport class. The properties inside the class must have a get and set method. The Dotag method needs to be rewritten, in effect this method actually completes the work of the label.
Create a TLD file
When creating, it is best to find a ready-made TLD file, copy it and then modify the URI (the UTI can tell the JSP page that the prefix should be directed to which TLD file corresponds), and then define the tag under the tag child element.
Taglib has the following three child elements:
Tlib-version: Specifies the tag library implementation version, no use
Short-name: Default short name, also no use
URI: Tag Library's unique identifier
Dynamic-attributes: Specifies whether the label supports dynamic properties and is only required when defining dynamic property tags.
Tag: The place where the tag library is defined. Each tag can contain Name,tag-class and body-content. The following four values can be set in a body-content:
Tagdependent: Specifies that the label handling class is responsible for handling the label body
Empty: Specifies that the label can only be used as an empty label
Scriptless: Specifies that the tag body can make static HTML elements, expression language, and cannot have scripts
JSP: Specifies that a JSP script can be used (not a JSP in JSP2)
Using the Tag Library
Use the tag library to first import with taglib compile instructions, to write the UTI prefix. Use prefix Plus: Spike signature.
Labels with attributes
You need to use the attribute child element when configuring. Each property corresponds to a sttribute. Each attribute needs to be configured with the name (property name), required (is required), fragment (whether JSP script is supported). Once configured, you will be prompted to enter the specified attribute when you use it. Here you can compare a label to a method, and by writing a method name, you can call the method. Importing taglib is equivalent to importing a jar package. Writing a prefix is equivalent to telling the program that I want to use the method inside the package.
Label with label body
Such tags can be embedded in the inside of other content to complete such as logical operations, loops and so on. General requirements body-content for scriptless.
Dynamic Property Labels
The Dynamicattributes interface needs to be implemented, overriding the Setdynamicattribute class. When configuring, you need to use Dynamic-attributes to annotate dynamic properties. You can optionally add attributes and property values when using tags. It seems that the program will automatically determine = Front is the property name, if so, then go to the set method, if not, OK, this is a dynamically generated property, hurriedly to create a.
This article from "Fingertip Light Fly" blog, declined reprint!
JSP note--7. Custom labels