`
jacky.jihao
  • 浏览: 152615 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

EL如何取得数组长度?EL取不了要靠JSTL

    博客分类:
  • J2EE
阅读更多

方法一: 使用JSTL functions

<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

 

 Eg:You have ${fn:length(shoppingCart.products)} in your shopping cart.

 

注意:这个标记和core不一样,它不能这样用 <fn:length(${commentsList}) />,这样会报类似于这样的一个异常:

org.apache.jasper.JasperException: /myshowpost.jsp(17,27) No tag "length(${commentsList})" defined in tag library imported with prefix "fn"

 

 

方法二: 使用<c:foreach status.count属性

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

用c:forEach 中vaStatus的属性可以获得迭代的自身状态,如:
<c:forEach var="" items="" varStatus="status">
<c:out value="${status.index}"/> 此次迭代的索引
<c:out value="${status.count}"/> 已经迭代的数量
<c:out value="${status.first}"/> 是否是第一个迭代对象
<c:out value="${status.last}"/>  是否是最后一个迭代对象
</c:forEach>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics