在 <c:if> 标签中使用 var 和 scope 属性

Usage of var and scope attributes in <c:if> tags

<c:if> 标签使用起来非常简单,但我不明白如何使用可选的 var 和 scope 属性。据说可以用这些来保存condition的result结果,但是如何呢?

如果标签之间的代码不是声明性的,或者如果它没有简单或直接地声明一个值怎么办,例如

  <c:if test = "${true}" var="testVar" scope="request">
     <p>not a declarative result  <c:out value = "${salary}"/></p>
  </c:if>

我尝试搜索示例但找不到任何示例。

阅读您发布的内容:"these can be used to save the result of the condition"。因此,标签正文中的任何内容都是无关紧要的。变量中保存的是条件的值(即真或假,在本例中为真)。

这可能很有用,例如为了替换

<c:if test="${someComplexConditionToEvaluate}">
  bla bla
</c:if>
<c:if test="${!someComplexConditionToEvaluate}">
  bla bla
</c:if>

来自

<c:if test="${someComplexConditionToEvaluate}" var="condition">
  bla bla
</c:if>
<c:if test="${!condition}">
  bla bla
</c:if>