繁体   English   中英

jstl条件不起作用

[英]jstl condition doesn't work

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

这有效。 正如所料,打印了“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>

这不起作用。 仅打印“ODD”:

<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>

有人可以帮帮我吗?

你错过了EL文字: ${..} 使用test="${true == true}"它会起作用。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM