zoukankan      html  css  js  c++  java
  • jstl进步篇

    <body>
    <h1>对map和set的迭代</h1>
    <%
    Map map = new HashMap();
    map.put("1", "aa");
    map.put("2", "bb");
    //把map放入某个域对象
    request.setAttribute("lstMap", map);

    //set
    Set set = new HashSet();
    User user = new User();
    user.setName("lihui");
    user.setAge(20);
    set.add(user);

    user = new User();
    user.setName("zhaoping");
    user.setAge(30);
    set.add(user);

    user = new User();
    user.setName("chengxiang");
    user.setAge(10);
    set.add(user);
    request.setAttribute("sets", new HashSet());
    request.setAttribute("lstSet", set);
    %>
    <h2>map</h2>
    <c:forEach items="${lstMap}" var="item">
    Key=${item.key };Value=${item.value }
    <!-- Key=2;Value=bb Key=1;Value=aa -->
    </c:forEach>

    <br/>
    <h2>set</h2>
    <c:forEach items="${lstSet}" var="item">
    ${item.name }:${item.age}
    </c:forEach>

    <br/>
    <h2>使用标签判断空</h2>
    <c:if test="${empty nihao}">
    没有该变量nihao
    </c:if>
    <br/>
    <c:if test="${empty sets}">
    没有元素sets
    </c:if>
    </body>

    输出:

    对map和set的迭代

    map

    Key=2;Value=bb Key=1;Value=aa

    set

    chengxiang:10 lihui:20 zhaoping:30

    使用标签判断空

    没有该变量nihao
    没有元素sets 

  • 相关阅读:
    java NIO 总结
    NIO 服务器和客户端 demo
    nio channel demo
    使用docker制作zookeeper镜像
    java BIO模型demo
    IDEA中语句添加try....catch..语句块
    线程的几种创建方式
    海豚调度Dolphinscheduler源码分析(四)
    @PostConstruct注解
    zookeeper常用命令
  • 原文地址:https://www.cnblogs.com/jiqiwoniu/p/jstl.html
Copyright © 2011-2022 走看看