trainingtrains Logo

91-9990449935

 0120-4256464

Iteration using JSP Custom Tag

We can iterate the body content of any tag using the doAfterBody() method of IterationTag interface.

Here we are going to use the TagSupport class which implements the IterationTag interface. For iterating the body content, we need to use the EVAL_BODY_AGAIN constant in the doAfterBody() method.

Example of Iteration using JSP Custom Tag

In this example, we are going to use the attribute in the custom tag, which returns the power of any given number. We have created three files here

  • index.jsp
  • PowerNumber.java
  • mytags.tld
index.jsp

PowerNumber.java

mytags.tld

Looping using Iteration Tag (creating tag for loop)

Let's create a loop tag that iterates the body content of this tag.

File: index.jsp
File: mytags.tld
File: Loop.java
File: web.xml

Output

Iteration Tag in JSP