c:if選擇標籤

1.jstl c 標籤實現判斷功能

單個判斷:
<c:if test="${resource.value=='GALL' && resource.checked == true}">
context here!
</c:if>
多重判斷:
<c:choose>
<c:when test="${resource.value=='GALL' && resource.checked == true}">
Your context here!
</c:when>
<c:otherwise>Your context here!</c:otherwise>
</c:choose>

 

 

<c:otherwise>

 
  在同一個 <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> 的本體內容。
 
  範例
 
  筆者舉一個典型的 <c:choose>、<c:when>和<c:otherwise>範例:
 
  <c:choose>
 
  <c:when test="${condition1}">
 
  condition1爲true
 
  </c:when>
 
  <c:when test="${ condition2}">
 
  condition2爲true
 
  </c:when>
 
  <c:otherwise>
 
  condition1和condition2都爲false
 
  </c:otherwise>
 
  </c:choose>
 
  範例說明:當condition1爲true時,會顯示“condition1爲true”;當condition1爲false且condition2爲true時,會顯示“condition2爲true”,如果兩者都爲false,則會顯示“condition1和condition2都爲false”。
 
  注意
 
  假若condition1和condition2兩者都爲true時,此時只會顯示"condition1爲true",這是因爲在同一個<c:choose>下,當有好幾個<c:when>都符合條件時,只能有一個<c:when>成立。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章