JSTL c:forTokens Core Tag

The JSTL Core Tag is used for the iteration process. It breaks the string into tokens by using delimiter and then iterate through tokens.

Syntax:

<c:forTokens items="string" delims="delimiter" var="varName">
          //block of statemtnts
</c:forTokens>

c:forTokens tag attributes:

AttributeDescriptionRequired
itemsInformation to loop over.No
beginElement to start with (0 = first item, 1 = second item, …).No
endElement to end with (0 = first item, 1 = second item, …).No
stepProcess every step items.No
varName of the variable to expose the current item.No
varStatusName of the variable to expose the loop status.No

Example:

test.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<html>
 <head>
  <title>c:forTokens JSTL core tag example</title>
 </head>
 <body>
  <h4>Tokens passed in the String "sunil, bharat, richi" are:</h4>
         <br/>
  <c:forTokens items="sunil, bharat, richi" delims="," var="name">
     <c:out value="${name}"/><p>
  </c:forTokens>
 </body>
</html>
web.xml
<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list> 
 
</web-app>

Output:


No comments: