jsp頁面中比較“接收資料”與“頁面迴圈資料”是否相等
阿新 • • 發佈:2018-12-06
頁面中關係運算符:
-lt 小於
-le 小於或者等於
-gt 大於
-ge 大於或者等於
-eq 等於
-ne 不等於
判空:<c:if test="${empty count }"></c:if>
例子:
//count=1 <c:if test="${count eq 1}">(equals)等於1</c:if> //count!=1 <c:iftest="${count ne 1}">(equals)不等於1</c:if> //count>=2 <c:if test="${count ge 2}">(gt eq)大於等於2<c:if> //count<2 <c:if test="${count le 2}">(lt eq小於等於2<c:if> //count>1 <c:if test="${count gt 1}">(gt)大於1<c:if> //count<1 <c:if test="${count lt 1}">(lt)大於1<c:if>
關於“沒有”的解決方案:
<c:if>沒有<c:else>可以用<c:choose>來取代結構: <c:choose> <c:when test=""> 如果 </c:when> <c:otherwise> 否則 </c:otherwise> </c:choose> 在同一個 <c:choose> 中,當所有 <c:when> 的條件都沒有成立時,則執行 <c:otherwise> 的本體內容。 語法 <c:otherwise> 本體內容 </c:otherwise> 屬性 無 限制 ·<c:otherwise> 必須在 <c:choose> 和 </c:choose>之間 ·在同一個 <c:choose> 中時,<c:otherwise> 必須為最後一個標籤 說明 在同一個 <c:choose> 中,假若所有 <c:when> 的test屬性都不為true時,則執行 <c:otherwise> 的本體內容。
例項:
1.兩個如果,選擇顯示true和false結果
<c:forEach var="i" begin="1" end="${num3}">//頁面迴圈 <c:if test="${ye3 eq i}">//如果成功 <a href="total_sel.action?ye3=${i}" style="color: #000">[${i}]</a> </c:if> <c:if test="${ye3 ne i}">//如果失敗(因為沒有else) <a href="total_sel.action?ye3=${i}" style="color: red">[${i}]</a> </c:if> </c:forEach>
2)
<c:choose> <c:when test="${ye2 eq i}"> 如果true,輸出結果 </c:when> <c:otherwise> 否則,輸出結果 </c:otherwise> </c:choose>
2.接收物件
<c:forEach items="${list3}" var="m"> <li> <a href="tileone_selectone.action?id=${m.id}"><img src="${m.picture}"></a> <div class="p-price">${m.name}<strong>¥${m.price}</strong></div> </li> </c:forEach>