JSTL's if else: with c:if without else processing

http://blog.csdn.net/xiyuan1999/article/details/4412009


if处理:
<c:if test="${pageCode=='mobileIndex'}">

......

</c:if>


JSTL 的 if else : 有 c:if 没有 else 的处理
结构:

<c:choose>

   <c:when test="">    如果
   </c:when>
  
   <c:otherwise>  否则
   </c:otherwise>
 
</c:choose>


代码:

<c:choose>
    <c:when test="${sessionScope.USERTYPE == 'inner'}">
      <c:set value="${context_root}/igmgr/MEB004.dow" var="action" scope="page"/>
    </c:when>
    <c:when test="${sessionScope.USERTYPE == 'merc'}">
      <c:set value="${context_root}/igmgr/MEB021.dow" var="action" scope="page"/>
    </c:when> 
   <c:otherwise> 
      <c:set value="${context_root}/igmgr/MEB020.dow" var="action" scope="page"/>
   </c:otherwise>
  </c :choose>

----------------------------------------------- --------------------------


Attachment: Detailed explanation + code


In the same <c:choose>, when all the conditions of <c:when> If none of them are established, execute the ontology content of <c:otherwise>.
  Syntax
  <c:otherwise>
  ontology content
  </c:otherwise>
  attribute
  None
  Restrictions
  <c:otherwise> must be between <c:choose> and </c:choose> when
  in the same <c:choose> , <c:otherwise> must be the last tag
  Description
  In the same <c:choose>, if all <c:when> When none of the test attributes are true, the ontology content of <c:otherwise> is executed.
  example
  The author gives a typical example of <c:choose>, <c:when> and <c:otherwise>:
  <c:choose>
  <c:when test="${condition1}">
  condition1 is true
  </c:when >
  <c:when test="${ condition2}">
  condition2 is true
  </c:when>
  <c:otherwise>
  both condition1 and condition2 are false
  </c:otherwise>
  </c:choose>
  Example: when When condition1 is true, it will display "condition1 is true"; when condition1 is false and condition2 is true, it will display "condition2 is true", if both are false, it will display "condition1 and condition2 are both false".
  Note that
  if both condition1 and condition2 are true, only "condition1 is true" will be displayed at this time, this is because under the same <c:choose>, when several <c:when> meet the conditions, Only one <c:when> can be true.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326849347&siteId=291194637