Custom Tags in JSP
Custom tags are user-defined tags. They eliminates the possibility of scriptlet tag and separates the business logic from the JSP page.
The same business logic can be used many times by the use of custom tag.
Advantages of Custom Tags
The key advantages of Custom tags are as follows:
Syntax to use custom tag
There are two ways to use the custom tag. They are given below:
JSP Custom Tag API
The javax.servlet.jsp.tagext package contains classes and interfaces for JSP custom tag API. The JspTag is the root interface in the Custom Tag hierarchy.
The JspTag is the root interface for all the interfaces and classes used in custom tag. It is a marker interface.
The Tag interface is the sub interface of JspTag interface. It provides methods to perform action at the start and end of the tag.
Fields of Tag interface
There are four fields defined in the Tag interface. They are:
Methods of Tag interface
The methods of the Tag interface are as follows:
The IterationTag interface is the sub interface of the Tag interface. It provides an additional method to reevaluate the body.
Field of IterationTag interface
There is only one field defined in the IterationTag interface.
Method of Tag interface
There is only one method defined in the IterationTag interface.
The TagSupport class implements the IterationTag interface. It acts as the base class for new Tag Handlers. It provides some additional methods also.