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

被折叠的 条评论
为什么被折叠?



