开发者社区> 问答> 正文

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

[“ 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]-数组列表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>

Servlet将列表传递给JSP

Scanner scanner  = new Scanner(Result);
        ControlData controlData = new ControlData();
        while(scanner.hasNextLine())  
        {  
            token1 = scanner.nextLine();
            Wtcs = controlData.CtrlWeight(token1);
            NC = controlData.NofConditions(token1);
            Ccspps = controlData.previousComplex(token1);

            cdLine.add(token1);
            wtc.add(Ccspps);
            ncc.add(NC);
            ccpps.add(Wtcs);

        }  

        List arr[]={cdLine,wtc,ncc,ccpps};   
        scanner.close();     //close the scanner  
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/views/Control_structures.jsp");
        request.setAttribute("Code_string", arr);
        dispatcher.forward(request, response);
    }
    ```
问题来源:Stack Overflow

展开
收起
montos 2020-03-23 10:21:27 843 0
1 条回答
写回答
取消 提交回答
  • 我得到了我问题的答案。

    在servlet中

            Scanner scanner  = new Scanner(Result);
            ControlData controlData = new ControlData();
            List<List<Comparable>> p =new ArrayList<List<Comparable>>();
            while(scanner.hasNextLine())  
            {  
                token1 = scanner.nextLine();
                Wtcs = controlData.CtrlWeight(token1);
                NC = controlData.NofConditions(token1);
                Ccspps = controlData.previousComplex(token1);
                List<Comparable> c =new ArrayList<Comparable>();
                c.add(token1);
                c.add(Wtcs);
                c.add(NC);
                c.add(Ccspps);
                p.add(c);
            }  
            scanner.close();     //close the scanner  
            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/views/jsp_page.jsp");
            request.setAttribute("Code_string", p);
            dispatcher.forward(request, response);
    

    现在,我有一个简单的列表来传递JSP。

    <c:forEach items="${Code_string}" var="post" varStatus="theCount1">
            <tbody>
    
                <tr>
                    <td>${post[0]}</td>
                    <td>${post[1]}</td>
                    <td>${post[2]}</td>
                    <td>${post[3]}</td>
                </tr>
            </tbody>
    </c:forEach>
    

    回答来源:Stack Overflow

    2020-03-23 10:22:20
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载