JSTL: for each loop
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt" %>
<%!
String[] names = { "Joe", "Rosy", "Sissi", "Sun" };
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>
Related examples in the same category