zoukankan      html  css  js  c++  java
  • JSP中forEach和forTokens循环的用法

    <%@page import="java.util.*"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        Map<String,String> map = new HashMap<String,String>();
        map.put("name", "つかだ");
        map.put("ads", "東京");
        map.put("phone", "080-1111-1111");
        list.add(map);
        map = new HashMap<String,String>();
        map.put("name", "たかはし");
        map.put("ads", "千葉");
        map.put("phone", "080-1111-2222");
        list.add(map);
        map = new HashMap<String,String>();
        map.put("name", "TTT");
        map.put("ads", "東京");
        map.put("phone", "080-1111-3333");
        list.add(map);
        request.setAttribute("list", list);
        
        String[][] ary_2 = new String[3][3];
        ary_2[0][0] = "つかだ";
        ary_2[0][1] = "東京";
        ary_2[0][2] = "080-1111-1111";
        ary_2[1][0] = "たかはし";
        ary_2[1][1] = "千葉";
        ary_2[1][2] = "080-1111-2222";
        ary_2[2][0] = "TTT";
        ary_2[2][1] = "東京";
        ary_2[2][2] = "080-1111-3333";
        request.setAttribute("ary_2", ary_2);
        
        String info = "つかだ,東京,080-1111-1111;たかはし,千葉,080-1111-2222;TTT,東京,080-1111-3333;";
        request.setAttribute("info", info);
    %>
    <table border="1">
        <tr>
            <th>名前</th>
            <th>住所</th>
            <th>電話NO</th>
        </tr>
        <c:forEach items="${ list }" var="map">
            <tr>
                <td>${ map.name }</td>
                <td>${ map.ads }</td>
                <td>${ map.phone }</td>
            </tr>
        </c:forEach>
    </table>
    <br/>
    <table border="1">
        <tr>
            <th>名前</th>
            <th>住所</th>
            <th>電話NO</th>
        </tr>
        <c:forEach items="${ ary_2 }" var="ary" varStatus="s">
            <tr>
                <td>${ ary[0] }</td>
                <td>${ ary[1] }</td>
                <td>${ ary[2] }</td>
            </tr>
        </c:forEach>
    </table>
    <br/>
    <table border="1">
        <tr>
            <th>名前</th>
            <th>住所</th>
            <th>電話NO</th>
        </tr>
        <c:forTokens items="${ info }" var="one" delims=";" >
            <tr>
                <c:forTokens items="${ one }" var="v" delims="," >
                    <td>${ v }</td>
                </c:forTokens>
            </tr>
        </c:forTokens>
    </table>
    </body>
    </html>
  • 相关阅读:
    面试题26:复杂链表的复制
    面试题25:二叉树中和为某一值的路径
    面试题24:二叉搜索树后序遍历
    面试题23:二叉树层序遍历
    面试题22:栈的压入,弹出序列
    面试题21:包含min函数的栈
    面试题20:顺时针打印矩阵
    面试题19:二叉树镜像
    plugin.go 源码阅读
    server.go 源码阅读
  • 原文地址:https://www.cnblogs.com/pangpanghuan/p/6738273.html
Copyright © 2011-2022 走看看