Use For Each to Loop Through Comma Delimited String : ForEach « JSTL « Java Tutorial






<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/core-rt" prefix="c-rt" %>
<html>
  <head>
    <title>Count to 10 Example(tracking even and odd)</title>
  </head>

  <body>
    <c:set var="days" value="A,B,C,D,E,F,G" />

    <table border="0">
      <c:forEach var="i" items="${days}" varStatus="status">
        <jsp:useBean id="status"
        type="javax.servlet.jsp.jstl.core.LoopTagStatus" />

        <c-rt:choose>
          <c-rt:when test="<%=status.getCount()%2==0%>">
            <c:set var="color" value="#cccccc" />
          </c-rt:when>

          <c-rt:otherwise>
            <c:set var="color" value="#dddddd" />
          </c-rt:otherwise>
        </c-rt:choose>

        <tr>
          <td width="200" bgcolor="<c:out value="${color}"/>"> 
          <c:out value="${i}" />
          </td>
        </tr>
      </c:forEach>
    </table>
  </body>
</html>
  Download:  JSTLUseForEachToLoopThroughCommaDelimitedString.zip( 1,226 k)








24.7.ForEach
24.7.1.JSTL ForEach Loop
24.7.2.JSTL ForEach Loop with Begin/End Step
24.7.3.JSTL Integer Controlled Loop
24.7.4.Use JSTL ForEach Tag to Loop Through a String
24.7.5.JSTL ForEach Status Count
24.7.6.JSTL ForEach Loop With Step
24.7.7.Reference Array by Index
24.7.8.Use For Each to Loop Through Comma Delimited String
24.7.9.Use ForEach to Loop Through ArrayList
24.7.10.Use JSTL ForEach to Loop through a Vector
24.7.11.Check Even Odd Number in ForEach Loop