JSTL标签库_3_cforEach_cforTokens
2014-10-29 14:11
211 查看
<c:forEach>标签用于对一个集合对象中的元素进行循环迭代操作,或者按指定的次数重复迭代执行标签体中的内容。
Item:代表集合,数组,map
Var:代表每次取到的变量。
Entry:对于map,每次获得的是一个entry,entry.key 键 entry.value 值。
Begin :开始 end结束 step步径。
VarStatus: index 目前下标,count总数,frist是否为首位,last是否为末尾
<h1>实验:遍历10到100的偶数,如果数字所在的位置是3的倍数,显示成红色</h1><hr>
<c:forEach begin="10" end="100" step="2" var="i" varStatus="stat">
<c:if test="${stat.count % 3 == 0}">
<font color="red">
${i }
</font>
</c:if>
<c:if test="${stat.count % 3 != 0}">
<font color="blue">
${i }
</font>
</c:if>
</c:forEach>
<h1>循环执行指定的内容若干次</h1><hr>
<c:forEach begin="0" end="10" step="2" var="i" >
${i },
</c:forEach>
<h1>遍历Map中的数据</h1><hr>
<%
Map map = new LinkedHashMap();
map.put("name","曹操");
map.put("age","59");
map.put("wife","小乔");
map.put("gender","男");
pageContext.setAttribute("map",map);
%>
<c:forEach items="${map}" var="entry" >
${entry.key }:${entry.value }<br>
</c:forEach>
<h1>遍历集合中的数据</h1><hr>
<%
List list = new ArrayList();
list.add("美国");
list.add("中国");
list.add("俄罗斯");
list.add("印度");
list.add("巴西");
pageContext.setAttribute("list",list);
%>
<c:forEach items="${list}" var="c">
${c }<br>
</c:forEach>
<h1>遍历数组中的数据</h1><hr>
<%
String [] city = {"北京","上海","广州","铁岭","葫芦岛"};
pageContext.setAttribute("city",city);
%>
<c:forEach items="${city}" var="c">
${c }<br>
</c:forEach>
<c:forTokens>用来浏览一字符串中所有的成员,其成员是由定义符号所分隔的
按照分隔符切割字符串,切割后相当于一个数组。遍历这个数组去进行操作。
<c:forTokens items="www.itheima.com" delims="." var="str">
${str }<br>
</c:forTokens>
Item:代表集合,数组,map
Var:代表每次取到的变量。
Entry:对于map,每次获得的是一个entry,entry.key 键 entry.value 值。
Begin :开始 end结束 step步径。
VarStatus: index 目前下标,count总数,frist是否为首位,last是否为末尾
<h1>实验:遍历10到100的偶数,如果数字所在的位置是3的倍数,显示成红色</h1><hr>
<c:forEach begin="10" end="100" step="2" var="i" varStatus="stat">
<c:if test="${stat.count % 3 == 0}">
<font color="red">
${i }
</font>
</c:if>
<c:if test="${stat.count % 3 != 0}">
<font color="blue">
${i }
</font>
</c:if>
</c:forEach>
<h1>循环执行指定的内容若干次</h1><hr>
<c:forEach begin="0" end="10" step="2" var="i" >
${i },
</c:forEach>
<h1>遍历Map中的数据</h1><hr>
<%
Map map = new LinkedHashMap();
map.put("name","曹操");
map.put("age","59");
map.put("wife","小乔");
map.put("gender","男");
pageContext.setAttribute("map",map);
%>
<c:forEach items="${map}" var="entry" >
${entry.key }:${entry.value }<br>
</c:forEach>
<h1>遍历集合中的数据</h1><hr>
<%
List list = new ArrayList();
list.add("美国");
list.add("中国");
list.add("俄罗斯");
list.add("印度");
list.add("巴西");
pageContext.setAttribute("list",list);
%>
<c:forEach items="${list}" var="c">
${c }<br>
</c:forEach>
<h1>遍历数组中的数据</h1><hr>
<%
String [] city = {"北京","上海","广州","铁岭","葫芦岛"};
pageContext.setAttribute("city",city);
%>
<c:forEach items="${city}" var="c">
${c }<br>
</c:forEach>
<c:forTokens>用来浏览一字符串中所有的成员,其成员是由定义符号所分隔的
按照分隔符切割字符串,切割后相当于一个数组。遍历这个数组去进行操作。
<c:forTokens items="www.itheima.com" delims="." var="str">
${str }<br>
</c:forTokens>
相关文章推荐
- JSTL 标签库<c:if> <:forEach> <:forTokens>
- JSTL 标签库<c:if> <:forEach> <:forTokens>
- JSTL Core标签库 c:if标签 条件标签 <c:forEach>:<c:forTokens>:迭代标签
- jstl <c:forTokens>标签,<c:forEach>标签
- JSTL <c:forEach>,<c:forTokens>标签
- <c:foreach><c:forTokens>
- JavaWeb - jstl标签库(if、forEach),jsp开发模式,mvc开发模式,Javaee三层结构,json插件
- jsp:jstl标签forTokens
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"(使用forEach时出错)
- <c:forEach>, <c:forTokens> 标签
- <c:forEach>, <c:forTokens> 标签
- <c:forEach>, <c:forTokens> 标签
- JSP 之 JSTL_04:<c:forTokens>
- Foreach循环及For性能及使用上的比较
- PHP中的循环while、do...while、for、foreach四种循环。
- 转载 JSTL标签库学习
- JSP中foreach标签(JSTL)的使用
- Objective-C中的For和ForEach循环(For and ForEach Loops in Objective-C )
- [测试分析] for与foreach 执行效率测试结果
- java关于for,foreach,iterator循环ArrayList的方式测试