当前位置:网站首页>Jsp使用<c:forEach>遍历List集合「建议收藏」
Jsp使用<c:forEach>遍历List集合「建议收藏」
2022-07-29 22:48:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
List<String> list = new ArrayList<String>();
list.add("简单是可靠的先决条件");
list.add("兴趣是最好的老师");
list.add("知识上的投资总能得到最好的回报");
request.setAttribute("list", list);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Jsp使用c:forEach遍历List集合</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<b>遍历List集合的全部元素:</b>
<br>
<c:forEach items="${requestScope.list}" var="keyword" varStatus="id">
${id.index} ${keyword}<br>
</c:forEach>
<br>
<b>遍历List集合中第一个元素以后的元素(不包括第一个元素):</b>
<br>
<c:forEach items="${requestScope.list}" var="keyword" varStatus="id" begin="1">
${id.index} ${keyword}<br>
</c:forEach>
</body>
</html>两层List遍历
<%
List list = new ArrayList();
List list1 = new ArrayList();
List list2 = new ArrayList();
list1.add("1-a");
list1.add("1-b");
list2.add("2-d");
list2.add("2-c");
list.add(list1);
list.add(list2);
request.setAttribute("list1", list1);
request.setAttribute("list", list);
%>
<c:forEach items="${list }" var="item">
<c:forEach items="${item }" var="item2">
<tr>
<td>${item2 }</td>
</tr>
</c:forEach>发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129762.html原文链接:https://javaforall.cn
边栏推荐
- 五、HikariCP源码分析之初始化分析二
- 百度智能云章淼:详解企业级七层负载均衡开源软件BFE
- leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
- Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE
- 一个print函数,挺会玩啊?
- ah?Now the primary test recruitment requirements will be automated?
- The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
- 新手如何写专利?
- 十一、HikariCP源码分析之HouseKeeper
- Topics in Dynamic Programming
猜你喜欢
随机推荐
7.联合索引(最左前缀原则)
你真的了解Redis的持久化机制吗?
MySQL的TIMESTAMP数据类型
我们上线了一个「开发者实验室」
ah?Now the primary test recruitment requirements will be automated?
设计消息队列存储消息的MySQL表格
聊聊阻容降压原理 和 实际使用的电路
互联网基石:TCP/IP四层模型,由浅入深直击原理!
JZ23 链表中环的入口结点
DD1 连续最大和
COPU陆首群教授应邀在ApacheCon Asia会议上致辞
How to realize object selection in canvas (5)
@Accessors 注解详解
PLSQL Developer安装和配置
【企业架构】企业架构框架的新资源出现
bgp基础配置和宣告
【C语言入门】ZZULIOJ 1036-1040
PyCharm使用教程(详细版 - 图文结合)
lambda表达式
把字符串转换成整数









