开发者

multiple <c:when> inside <c:choose>

开发者 https://www.devze.com 2023-04-08 14:06 出处:网络
I am just wondering whether the below code is valid? <c:choose> <c:when test=\"${empty example1}\">

I am just wondering whether the below code is valid?

<c:choose>
    <c:when test="${empty example1}">
    </c:when>
    <c:when test="${empty example2}">
    </c:when>
    <c:otherwise>
  开发者_开发知识库  </c:otherwise>              
</c:choose>


In a c:choose, the first when for which the test is true is the winner. In the c:choose below, if "first test" and "second test" are both true, then the "Kpow" h2 will be added to the html page and the "Blammy" will not.

<c:choose>
  <c:when test="first test">
    <h2>Kpow</h2>
  </c:when>
  <c:when test="second test">
    <h2>Blammy</h2>
  </c:when>
</c:choose>


<c:choose>
    <c:when test="${empty example1}">
    </c:when>
  <c:when test="${empty example2}">
  </c:when>
  <c:otherwise>
  </c:otherwise>              
</c:choose>

This code is nothing but

 switch(int i){
   case 1:
   ...
   break;
   case 2:
   ...
   break;
   default:
   ...
   break;
}


Yes its valid. Why not just try it though? Look up JSTL for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号