六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 26|回复: 0

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

[复制链接]

升级  21.33%

20

主题

20

主题

20

主题

秀才

Rank: 2

积分
82
 楼主| 发表于 2013-1-27 04:53:03 | 显示全部楼层 |阅读模式
方法一: 使用JSTL functions
<[email=%@taglib]%@taglib[/email] 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属性
<[email=%@taglib]%@taglib[/email] 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>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表