当前位置:网站首页>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
边栏推荐
- Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE
- Sorry, it's hard for you to earn middle-aged money
- lambda表达式
- C语言快速入门(为了看源码)
- 高性能数据访问中间件 OBProxy(三):问题排查和服务运维
- chrome集成沙拉查词
- 利用go通道channel实现互斥锁
- BGP联邦综合实验
- 六、HikariConfig配置解析
- Redis和MySQL如何保持数据一致性
猜你喜欢
随机推荐
真offer收割机 第二弹~大厂如何考察候选人?(附答案详解)
JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
研究生怎么申请专利,流程是什么?
六、HikariConfig配置解析
A print function, very good at playing?
leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
访问公司内网
【面试:并发篇30:多线程:happen-before】
网工知识角|轻松拿offer【网工面试题】三层交换机与路由器有什么区别?
【面试:并发篇33:cas】原子更新器 原子累加器 缓存一致性问题
JZ6 从尾到头打印链表
外文论文的格式规范要求有哪些?
【C语言入门】ZZULIOJ 1036-1040
邮件服务器配置「建议收藏」
JZ24 反转链表
刀具更换策略问题(完工)
The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
【luogu P8354】多边形(容斥)(NTT优化DP)
Three chess (written in C language)
超分之RVRT









