foreach如何在JSP中使用列表列表

问题描述 投票:0回答:1

[[“ A”,“ B”,“ C”,“ D”,“ E”,“ F”]-ArrayList 01

[[1,2,3,4,5,6]-ArrayList 02

[[10,20,30,40,50,60]-ArrayList 03

[100,200,300,400,500,600]-ArrayList 04

Main_List-[[“ A”,“ B”,“ C”,“ D”,“ E”,“ F”],[1,2,3,4,5,6],[10,20,30,40, 50,60],[100,200,300,400,500,600]];

  • Main_List是四个数组列表的组合

如何将Main_List检索到具有四列的表中?

<c:forEach items="${List_parameter}" var="post" varStatus="theCount">
    <tbody>
        <c:forEach items="${post}" var="value" varStatus="cell">
            <tr>
                <td scope="row">${theCount.count}</td>
                <td>${value.get(0)}</td>
                <td>${value.get(1)}</td>
                <td>${value.get(2)}</td>
                <td>${value.get(3)}</td>
                <td>-</td>
            </tr>
        </c:forEach>
    </tbody>
</c:forEach>
java jsp foreach jstl nested-loops
1个回答
0
投票

1)使用评估EL

2)创建列表并添加。

3)设置pageContext.setAttribute(“ list”,finalList);

<!DOCTYPE html>
<%@ page isELIgnored="false"%>
<%@ page language="java" contentType="text/html"%>
<%@ page import="java.util.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List</title>
</head>
<body>
    <h1>List</h1>
    <%
        List<String> list1 = Arrays.asList("A", "B", "C", "D", "E", "F", "G");
        List<Integer> list2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
        List<List> finalList = new ArrayList<>();
        finalList.add(list1);
        finalList.add(list2);
        pageContext.setAttribute("list", finalList);
    %>
    <c:forEach items="${list}" var="post" varStatus="theCount">
        <p>List ${theCount.count}</p>
        <c:forEach items="${post}" var="value" varStatus="cell">
            ${value} &nbsp;
        </c:forEach>
    </c:forEach>
</body>
</html>

//输出//

列表清单1

A B C D E F G清单2

1 2 3 4 5 6 7

© www.soinside.com 2019 - 2024. All rights reserved.