【jstl】jsp标准标签库——标签使用方法整理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31083947/article/details/78700632

1、c:if (没有c:else)

<c:if test="${age > 20}">age大于20</c:if> //age大于20时,返回true

<c:if test="${falg}">flag为true</c:if> //flag是一个布尔值,如果不是,那么页面会有类型不匹配的报错

<c:if test="${empty str}">str为空</c:if>//判空,相当于<s:if test="str==''"></s:if>

<c:if test="${not empty str}">str不为空</c:if>//判空,相当于<s:if test="str!=''"></s:if>

2、c:forEach

<c:forEach items="${users}" var="user" varStatus="s">
    序号:${s.index+1}//索引从0开始
    用户名:${user.name}
    年龄:${user.age}
</c:forEach>

items:后台传来的一个集合,这里接受的集合,不支持数组
var:相当于for(User user:users){}中的user,从集合中取出的临时对象
varStatus:当前foreach的状态,可以获取当前迭代到了第几个对象 如:${s.index}即为获取当前对象的索引

猜你喜欢

转载自blog.csdn.net/qq_31083947/article/details/78700632