JSTL 中的相等判断和选择和非空判断的知识点

本文详细介绍了JSTL中的条件语句使用方法,包括如何进行简单的条件判断及复杂的多级条件分支处理。通过具体实例展示了如何使用<c:if>、<c:choose>、<c:when>和<c:otherwise>等标签来实现逻辑控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                     1> 关于JSTL中的选择 

               当在JSP 页面中 需要判断某个属性相等于多少数值的时候,

               这个时候不是用“==”或者.equal(),等判断,而是根据其本身标签库提供的一个函数判断:  eq

               例如:

               //判断标志位是否为 0

               <c:if test="${item.flag eq 0}"></c:if>

                2> JSTL 关于选择的情况

                 JSTL 中有选择的如果属性<c:if> 然而,却没有否则属性,如果,先使用 如果……否则 的判断关系,就必须使用

               <c:choose

                         <c:when>  </c:when>

                         <c:otherwise></c:otherwise>

               </c:choose>

              例如:

               <c:choose>
                    <c:when test="${item.flag eq 0}">
                        <tr>
                            <td height="32" colspan="3" style="font-size: 18px; color: red">${item.startTime}</td>
                        <tr>
                    </c:when>
                    <c:otherwise>
                        <tr>
                            <td height="32" colspan="3" style="font-size: 18px; color:green">${item.startTime}</td>
                        </tr>
                    </c:otherwise>
            </c:choose>   


        2.1> 当然,其实 JSTL 中选择判断的属性也是可以嵌套使用的:

          例如:

          <c:choose>
            <c:when test="${item.flag eq 2}">
                <tr>
                    <td height="32" colspan="3" style="font-size: 18px; color: black">${item.startTime}</td>
                <tr>
            </c:when>
            <c:otherwise>
                 <c:choose>
                    <c:when test="${item.flag eq 0}">
                        <tr>
                            <td height="32" colspan="3" style="font-size: 18px; color: red">${item.startTime}</td>
                        <tr>
                    </c:when>
                    <c:otherwise>
                        <tr>
                            <td height="32" colspan="3" style="font-size: 18px; color: green">${item.startTime}</td>
                        </tr>
                    </c:otherwise>
            </c:choose>               
            </c:otherwise>
        </c:choose>

              


                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值