How to come out of if tag of JSTL , like using break in C if loop.
I am using Jstl if tag to check condition I would开发者_如何学编程 like to know ,How to come out of if tag of JSTL , like using break in C if loop.
The simplest way to break out of a loop is to use a boolean variable.
example:
<c:set var="conditionVariable" value ="true"/>
<c:forEach ..>
<c:if test="${conditionVariable eq 'true'}>
<!-- code that should be execute --!>
<c:if> - your condition
<c:set var="conditionVariable" value="false"/>
</c:if>
</c:if>
</c:forEach>
You can write your own break tag, as shown here.
You can also try setting the loop status variable to the index of the last element in the collection (but I have never tried this).
精彩评论