jstl if else选择/何时不评估变量

时间:2012-11-28 21:57:36

标签: jsp jstl el

我正在尝试在满足选择/何时条件时打印一些html:

 <c:choose>
      <c:when test="${notification.placeId} == ${place.placeId}">
    ${notification.name}
  </c:when>
<c:otherwise>
    placeId: ${place.placeId} - notplaceid: ${notification.placeId}
    </c:otherwise>
 </c:choose>

这打印:  placeId:50 - notplaceid:43 placeId:50 - notplaceid:47 placeId:50 - notplaceid:49 placeId:50 - notplaceid:50 placeId:50 - notplaceid:51 placeId :50 - notplaceid:51 placeId:50 - notplaceid:51 placeId:50 - notplaceid:51 placeId:50 - notplaceid:52 placeId:50 - notplaceid:53 placeId:50 - notplaceid:0 placeId:50 - notplaceid:0

这一切都打印出来,否则永远不会从when语句中打印通知名称。从打印件中可以看出,粗体输出明显符合when条件,并应打印通知名称。

有谁知道发生了什么事?

1 个答案:

答案 0 :(得分:5)

使用

<c:when test="${notification.placeId == place.placeId}">

而不是

<c:when test="${notification.placeId} == ${place.placeId}">

您键入它的方式,test属性被评估为字符串:${notification.placeId}==的评估结果和评估结果的串联${place.placeId}

您希望将整个事物评估为布尔表达式。