JSTL c:forEach,递减循环不可能? [英] JSTL c:forEach, decremental number loop impossible?
本文介绍了JSTL c:forEach,递减循环不可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< c:forEach var =ibegin =10 end =0step = - 1>
... $ {i} ...
< / c:forEach>
然后我得到了jsp异常:
javax.servlet.jsp.JspTagException:'step'< = 0
javax.servlet.jsp.jstl.core.LoopTagSupport.validateStep(LoopTagSupport.java:459)
org.apache.taglibs.standard.tag.rt.core.ForEachTag.setStep(ForEachTag.java:60)
....
但是这个答案表示可以循环两种方式:
我有什么问题吗?
解决方案
我不确定其他问题的回答者是如何工作的,但是我不能用引用JSTL
无论如何,您可以通过以下方式达到要求:
< c:forEach var =ibegin =0end =10step =1>
... $ {10 - i} ...
< / c:forEach>
或者如果您想避免重复 10
$ b $ $ $ p $ < c:forEach var =ibegin =0end =10step = 1varStatus =loop>
... $ {loop.end - i + loop.begin} ...
< / c:forEach>
I want to print decremental numbers like:
<c:forEach var="i" begin="10" end="0" step="-1">
... ${i} ...
</c:forEach>
then I got jsp exception:
javax.servlet.jsp.JspTagException: 'step' <= 0
javax.servlet.jsp.jstl.core.LoopTagSupport.validateStep(LoopTagSupport.java:459)
org.apache.taglibs.standard.tag.rt.core.ForEachTag.setStep(ForEachTag.java:60)
....
but this answer says it is possible to loop in both ways:
What's wrong with me?
解决方案
I am not sure how the answerer of the other question got it to work, but I can't get it to work here with the reference JSTL implementation.
Anyway, you can achieve the requirement with following:
<c:forEach var="i" begin="0" end="10" step="1">
... ${10 - i} ...
</c:forEach>
Or if you'd like to avoid duplication of 10
:
<c:forEach var="i" begin="0" end="10" step="1" varStatus="loop">
... ${loop.end - i + loop.begin} ...
</c:forEach>
这篇关于JSTL c:forEach,递减循环不可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文