91-9990449935 0120-4256464 |
Custom Tags in JSPCustom 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 TagsThe key advantages of Custom tags are as follows:
Syntax to use custom tagThere are two ways to use the custom tag. They are given below: JSP Custom Tag APIThe 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. JspTag interfaceThe JspTag is the root interface for all the interfaces and classes used in custom tag. It is a marker interface. Tag interfaceThe 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 interfaceThere are four fields defined in the Tag interface. They are:
Methods of Tag interfaceThe methods of the Tag interface are as follows:
IterationTag interfaceThe IterationTag interface is the sub interface of the Tag interface. It provides an additional method to reevaluate the body. Field of IterationTag interfaceThere is only one field defined in the IterationTag interface.
Method of Tag interfaceThere is only one method defined in the IterationTag interface.
TagSupport classThe TagSupport class implements the IterationTag interface. It acts as the base class for new Tag Handlers. It provides some additional methods also.
Understanding Flow and Example of JSP Custom Tag
There is given two simple examples of JSP custom tag. One example of JSP custom tag, performs action at the start of the tag and second example performs action at the start and end of the tag. Attributes in Custom Tag Here, we will learn how we can define attributes for the custom tag. Iteration using Custom Tag In this example, we are iterating the body content of the custom tag. Custom URI in Custom Tag We may also refer the TLD file by using the URI. Here we will learn how can we use custom URI.
Next TopicExample Of Jsp Custom Tag
|