[英]jstl condition doesn't work
I can't understand how is that possible, so i will just show the code. 我无法理解这是怎么可能的,所以我只会展示代码。
This works. 这有效。 As expected, a list of "PAIR" is printed: 正如所料,打印了“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>
This doesn't work. 这不起作用。 Print only "ODD": 仅打印“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>
Someone can help me? 有人可以帮帮我吗?
You are missing the EL literal: ${..}
. 你错过了EL文字: ${..}
。 Use test="${true == true}"
and it will work. 使用test="${true == true}"
它会起作用。
The first example works because the string true
, when converted to boolean, is true
. 第一个示例有效,因为字符串true
在转换为boolean时为true
。 The parser tries to convert the string-value you passed to boolean using Boolean.valueOf(..)
. 解析器尝试使用Boolean.valueOf(..)
将传递的字符串值转换为boolean。 And a conversion of the true == true
string, using Boolean.valueOf(..)
gives you false
. 使用Boolean.valueOf(..)
转换true == true
字符串会给出false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.