Reference Array by Index : 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" %>

<%!
  String[] names = { "A","B", "C", "D" };
  int[]    ages  = { 29, 8, 6, 5};
%>

<HTML>
  <HEAD><TITLE>JSTL 'forEach' tag</TITLE></HEAD>
  <BODY>
    <H1>List of people</H1>
    <TABLE BORDER="1">
      <TH>Name</TH>
      <c-rt:forEach var="person" items="<%= names %>">
        <TR>
          <TD><c:out value="${person}"  /></TD>
          <TD><c:out value="${ages[i]}" /></TD>
        </TR>
      </c-rt:forEach>
    </TABLE>
  </BODY>
</HTML>
  Download:  JSTLReferenceArrayByIndex.zip( 938 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