EL标签 set if choose forEach

set标签可以往域中保存数据

        scope  设置保存到哪个域
        var    属性值的key
        value  属性的值

    <c:set scope="request" var="key1"  value="cuijintao"/>
    ${requestScope.key1}<br/>


if标签用来做if判断

        test属性表示判断的条件 (条件表达式用el表达式输出)

    <c:if test="${12 > 1}">
        我是个好人<br/>
    </c:if>



<c:choose> <c:when> <c:otherwise>标签
        类似于switch ... case ... default

        choose 开始选择判断
        when   表示每一种判断情况
            test 属性表示当前这种判断情况的值
        otherwise 标签表示剩下的情况

        <c:choose> <c:when> <c:otherwise>标签使用需要注意的点:
            1.标签里不能有html注释,要使用jsp注释.
            2.when标签的父标签一定是 choose标签


    <%
        request.setAttribute("grade",89);
    %>
    <c:choose>
        <c:when test="${requestScope.grade>=90}">
            <h4>成绩优秀</h4>
        </c:when>
        <c:when test="${requestScope.grade>=80}">
            <h4>成绩良好</h4>
        </c:when>
        <c:when test="${requestScope.grafe>=70}">
            <h4>成绩及格</h4>
        </c:when>
        <c:otherwise>
            <h4>成绩不合格</h4>
        </c:otherwise>
    </c:choose>
   

forEach 标签  用来遍历输出
            begin 开始的索引
            end   结束的索引
            var   属性表示循环的变量(也是当前遍历到的数据)
            items 表示遍历的集合
            step  遍历的步长值 默认为1
            varStatus 表示当前遍历到的数据的状态

    <%-- 1.遍历输出1到10 --%>
    <c:forEach begin="1" end="10" var="i">
        ${i}<br/>
    </c:forEach>
    <hr/>
    <%-- 2.遍历对象数组 --%>
    <%
        request.setAttribute("arr",new String[]{"110","120","119"});
    %>
    <c:forEach items="${requestScope.arr}" var="i">
        ${i}<br/>
    </c:forEach>
    <%-- 3.遍历map --%>
    <%
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("key1","value1");
        map.put("key2","value2");
        map.put("key3","value3");
        request.setAttribute("map",map);
    %>
    <c:forEach items="${requestScope.map}" var="i">
        ${i.key} = ${i.value}
    </c:forEach>

    <%-- 4.遍历list集合 --%>
    <%
        List<Student> studentList=new ArrayList<Student>();
        for (int i = 0; i < 10 ; i++) {
            studentList.add(new Student(0+i,"username"+i,"password"+i,18+i,"phone"+i));
        }
        request.setAttribute("students",studentList);
    %>
    <table border="1" align="center" cellpadding="0" cellspacing="0">
        <c:forEach items="${requestScope.students}" var="student">
            <tr>
                <td>${student.id}</td>
                <td>${student.username}</td>
                <td>${student.password}</td>
                <td>${student.age}</td>
                <td>${student.phone}</td>
            </tr>
        </c:forEach>
    </table>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值