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

来源:互联网 发布:mac 应用程序目录 编辑:程序博客网 时间:2024/06/15 12:29

                     1> 关于JSTL中的选择 

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

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

               例如:

               //判断标志位是否为 0

               <c:if test="${item.flag eq0}"></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>

              


                 


原创粉丝点击