Tag Handlers in JSP
by, 07-07-2012 at 07:54 PM (1848 Views)
The Java Server Pages container invokes the tag handler object in order to evaluate custom tags that are referened by other tags while JSP page is being executed. The Java Server Pages implementation class calls the tag handler methods at different phases of tag evaluation.
The Java Server Pages invokes the doStartTag method handler so that an appropriate method handler is initialized when ever a start tag is encountered of a custom tag. The Java Server Pages invokes the doEndTag method handler when it encounters the end tag of a custom tag. Many other methods are invoked when handler needs to interact with the tag body.
To communicate with the Java Server Page, an API access is provided to the tag handler. The page context object provide the API entry point and using this context object all the implicity objects are accessed by the tag handler like session, application and request. Different attributes are associated with the implicity object. These associated attributes are accessed using getter and setter methods. In case of nested tag, the tag handlers can also access the parent tag handler that is attached with the enclosing tag. The BodyTag or Tag interfaces are implemented by the tag handlers. Existing Java objects are used by the interfaces to create a tag handler. The BodyTagSupport and TagSupport classes are used for newly created handlers.