更改<c:set jstl tag的值

joh*_*ohn 4 java jsp jstl

我在我的jsp上使用以下表达式

<c:set var="flag" value="false" />
Run Code Online (Sandbox Code Playgroud)

我在每个循环中有一个条件,我可能想要将此变量更改为true.有没有办法做到这一点.我到处寻找但无法找到解决方案.

Ram*_*PVK 9

以下是您要查找的示例代码:

<c:choose>
   <c:when test="${yourcondition}">
      <c:set var="flag" value="true" />
   </c:when>
   <c:otherwise>
      <c:set var="flag" value="false" />  
   </c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)


sto*_*ter 6

为什么不在循环中重用相同的代码

<c:set var="flag" value="true" />
Run Code Online (Sandbox Code Playgroud)


Vij*_*ndi 5

你也可以这样做

<c:set var="flag" value="${(yourcondition)? true : false}"/>
Run Code Online (Sandbox Code Playgroud)