请给出JSTL里面的c:forEach标签例子

JSTL c:forEach标签使用示例
本文介绍如何使用JSTL中的c:forEach标签来遍历并显示ArrayList集合的内容,通过具体代码示例展示了如何设置变量、迭代范围及步长。

7)c:forEach标签 
完成诸如显示ArrayList内容的功能:
例 2.2.7
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<%
   ArrayList books=new ArrayList();
   books.add(new String("java入门"));
   books.add(new String("JSTL入门"));
   books.add(new String("C++精通"));
   books.add(new String("C++精通2"));
   books.add(new String("C++精通3"));
   books.add(new String("C++精通4"));
 /*note that you must use the following stetement to make the code inside scriptlet available
to the jsp page. */
   pageContext.setAttribute("booksq",books);
%>
   <c:forEach var="book" items="${booksq}" begin="1" end="3" step="1">
      <c:out value="${book}"/><br>
   </c:forEach>
</body>
</html>
 

更多请见:http://www.mark-to-win.com/tutorial/jsp_5_cforEachExample.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值