|
Iterator Tags
The <c:forEach> tag allows you to iterate over a collection of objects. You specify the collection via "items" attribute, and the current item is available through a variable named given in the "var" attribute. A large number of collection types are supported by <c:forEach>, including all implementations of java.util.Collection and java.util.Map. If given collection is of type java.util.Map, then the current item will be of type java.util.Map.Entry, which has the following properties:
- key: The key under which the item is stored in the underlying Map
- value: The value that corresponds to the key
Arrays of objects as well as arrays of primitive types (for example, int) are also supported. For arrays of primitive types, the current item for the iteration is automatically wrapped with its standard wrapper class (for example, Integer for int, Float for float, and so on).
<c:forEach var="item" items="collection"> </c:forEach> or
<c:forEach begin="0" end="10" varStatus="status" step="1" >
</c:forEach>
URL Tags
The <c:url> tag is used to create the URL for the submit actions or the hyperlinks. The <c:url> tag is used to create the URL variable and <c:param> is used to add the parameters in the <c:url> tag. The syntax is as follows:-
<c:url var="var" value="..." > <c:param name="param1" value="val1" /> </c:url>
Example:-
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %> <% String[] value = new String[10]; value[0]="one"; value[1]="two"; value[2]="three"; value[3]="four"; value[4]="five"; value[5]="six"; value[6]="seven"; value[7]="eight"; value[8]="nine"; value[9]="ten"; pageContext.setAttribute("values",value); %> <b>Iterator For loop <br></b> <c:forEach var="item" varStatus="status" items="${values}"> Place <c:out value="${status.index}"/> value is <c:out value="${item}"/><br> </c:forEach> <br> <b>Coventional For Loop<br></b> <c:forEach begin="0" end="10" varStatus="status" step="1" > Place <c:out value="${status.index}"/> value is <c:out value="${values[status.index]}"/><br> </c:forEach>
<c:url var="yahoo" value="http://www.yahoo.com"/>
<a href="${yahoo}">yahoo url</a>
|