The labels of the packages in Java for, while, do-while loop.
In contrast, <c: forEach> tag is more generic label, because it iterative objects in a collection.
<C: forTokens> tag delimiter strings separated by a specified iteration and array them.
forEach syntax
<c:forEach items="<object>" begin="<int>" end="<int>" step="<int>" var="<string>" varStatus="<string>"> ...
forTokens syntax
<c:forTokens items="<string>" delims="<string>" begin="<int>" end="<int>" step="<int>" var="<string>" varStatus="<string>">
Attributes
<C: forEach> tag has the following attributes:
Attributes | description | If necessary | Defaults |
---|---|---|---|
items | Information to be circulated | no | no |
begin | Element start (0 = first element, the second element = 1) | no | 0 |
end | The last element (0 = first element, the second element = 1) | no | Last element |
step | Each iteration step | no | 1 |
where | Entry represents the current variable name | no | no |
varStatus | State representatives loop variable name | no | no |
<C: forTokens> tag and <c: forEach> tag has similar properties, but <c: forTokens> there is another property:
Attributes | description | If necessary | Defaults |
---|---|---|---|
delims | Separator | Yes | no |
<C: forEach> Example Demo
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:forEach 标签实例</title> </head> <body> <c:forEach var="i" begin="1" end="5"> Item <c:out value="${i}"/><p> </c:forEach> </body> </html>
Results are as follows:
Item 1
Item 2 Item 3 Item 4 Item 5
<C: forTokens> Demo Examples
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:forTokens 标签实例</title> </head> <body> <c:forTokens items="google,runoob,taobao" delims="," var="name"> <c:out value="${name}"/><p> </c:forTokens> </body> </html>
Results are as follows:
google
runoob
taobao