Empty Custom Tag Without Attributes
Let's look next at a very simple custom tag. The tag library corresponding to the first taglib directive shown in the previous section describes an action for a tag named currenttime. That description is in the following XML element in the TLD file:
<tag> <name> currenttime </name> <tagclass> org.apache.taglibs.datetime.CurrentTimeTag </tagclass> <bodycontent> empty </bodycontent> <info> Gets the current time in milliseconds since Jan 1, 1970 GMT. </info> </tag>
The info tag should tell you what action to expect from adding the tag to a JSP. In any page that contains the datetime taglib directive, each of the action elements belonging to the datetime tag library must appear with a "dt" prefix, as follows:
<dt:currenttime/>
A JSP custom tag can hardly get any simpler than this example. As you see in the tag element in the TLD file for the currenttime action, this tag has an empty body content. That is equivalent to having a body with nothing in it; note that because whitespace here is ignored, the last tag example can also be written on a JSP using both a start tag and an end tag, without element content, like this:
<dt:currenttime> <dt:currenttime/>
Custom tags take on more complex actions in two ways:
Using attributes to pass information from the JSP to the Tag Handler class
Processing body content, whatever is between the start tag and the end tag