jstl条件不起作用

时间:2012-02-08 19:54:14

标签: java jsp jstl el

我无法理解这是怎么可能的,所以我只会展示代码。

这很有效。正如所料,一个" PAIR"打印出来:

<c:forEach var="element" items="${list}">
<c:choose>
    <c:when test="true">
       <div>PAIR ${element}</div>
    </c:when>
    <c:otherwise>
       <div>ODD ${element}</div>
    </c:otherwise>
</c:choose>
</c:forEach>

这不起作用。仅打印&#34; ODD&#34;:

<c:forEach var="element" items="${list}">
<c:choose>
    <c:when test="true == true">
       <div>PAIR ${element}</div>
    </c:when>
    <c:otherwise>
       <div>ODD ${element}</div>
    </c:otherwise>
</c:choose>
</c:forEach>

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:6)

您缺少EL文字:${..}。使用test="${true == true}"即可使用。

第一个示例有效,因为字符串true在转换为布尔值时为true。解析器尝试使用Boolean.valueOf(..)将传递的字符串值转换为布尔值。使用true == true转换Boolean.valueOf(..)字符串会为您提供false