JavaWeb-JSP-JSTL c foreach -2023-04-09

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>foreach</title>
</head>
<body>
<%
    ArrayList<String> people = new ArrayList<>();
    people.add(0,"张三");
    people.add(1,"李四");
    people.add(2,"王五");
    people.add(3,"赵六");
    people.add(4,"朱七");
    request.setAttribute("list",people);
%>

<c:forEach var="people" items="${list}">
    <c:out value="${people}"/> <br>
</c:forEach>
<hr>
<c:forEach var="people" items="${list}" begin="1" end="4" step="2">
    <c:out value="${people}"/> <br>
</c:forEach>
</body>
</html>

输出结果

张三
李四
王五
赵六
朱七


李四
赵六

posted @ 2023-04-09 15:42  Rui2022  阅读(18)  评论(0编辑  收藏  举报