What is the difference between and ?

后端 未结 2 768
广开言路
广开言路 2021-02-05 02:04

I\'ve noticed usages of in one place of JSP code and in the other. The things they do look the same for me. Are the

相关标签:
2条回答
  • 2021-02-05 02:12

    <c:if is a simple if-clause. <c:when> has options for multiple if-clauses and an else clause. Compare:

    <c:if test="${foo == 'bar'}">...</c:if>
    

    with

    <c:choose>
       <c:when test="${foo == 'bar'}">...</c:when>
       <c:when test="${foo == 'baz'}">...</c:when>
       <c:otherwise>...</c:otherwise>
    </c:choose>
    
    0 讨论(0)
  • 2021-02-05 02:22

    <c:if> doesn't support any kind of "else" or "else if" functionality. <c:when> does. So if you need something analogous to

    if (some_condition) {
        // ...
    }
    

    then use <c:if>. If you need something analogous to

    if (some_condition) {
        // ...
    } else if (some_other_condition) {
        // ...
    } else {
        // ...
    }
    

    then use <c:choose> with <c:when> and (optionally) <c:otherwise>.

    0 讨论(0)
提交回复
热议问题