JSP 标准标签库(JSTL)中C标签的用法

c:forEach varStatus属性


current当前这次迭代的(集合中的)项
index当前这次迭代从 0 开始的迭代索引
count当前这次迭代从 1 开始的迭代计数
first用来表明当前这轮迭代是否为第一次迭代的标志
last用来表明当前这轮迭代是否为最后一次迭代的标志
begin属性值
end属性值
step属性值 


我们常会用c标签来遍历需要的数据,为了方便使用,varStatus属性可以方便我们实现一些与行数相关的功能,如:奇数行、偶数行差异;最后一行特殊处理等等。先就varStatus属性常用参数总结下:


${status.index}      输出行号,从0开始。
${status.count}      输出行号,从1开始。
${status.current}   当前这次迭代的(集合中的)项
${status.first}  判断当前项是否为集合中的第一项,返回值为true或false
${status.last}   判断当前项是否为集合中的最后一项,返回值为true或false
begin、end、step分别表示:起始序号,结束序号,跳跃步伐。


如:

表示:操作list集合汇中1~5条数据,不是逐条循环,而是按每2个取值。即操作集合中的第1、3、5条数据。


一个分页表格的显示例子

JSP 标准标签库(JSTL)中C标签的用法_第1张图片



欢迎你: ${sessionScope.user.username}

用户展示

cellspacing="0" cellspadding="0" border="1"> <c:forEach var="u" items="${pages.list}" varStatus="status"> <c:choose><c:when test="${u.status == 1}"><c:set var="sta" value="正常">c:set> c:when> <c:when test="${u.status == 2}"> <c:set var="sta" value="离职">c:set> c:when> c:choose> <c:choose><c:when test="${u.role == 1}"><c:set var="role" value="普通人员">c:set> c:when> <c:when test="${u.role == 2}"> <c:set var="role" value="管理员">c:set> c:when> <c:when test="${u.role == 3}"> <c:set var="role" value="超级管理员">c:set> c:when> c:choose> c:forEach>
序号 用户名 状态 角色 修改状态 修改角色权限 修改角色密码
${status.count+(pages.curIndex-1)*10} ${u.username} ${sta} ${role} href="LoadUpdateUserServlet?id=${u.id}&operation=${"status"}">修改状态 href="LoadUpdateUserServlet?id=${u.id}&operation=${"role"}">修改权限 href="LoadUpdateUserServlet?id=${u.id}&operation=${"password"}">修改密码
href="ListByPageServlet?curIndex=${pages.curIndex==1?1:pages.curIndex-1}">上一页 <c:forEach var="p" begin="1" end="${pages.totalPage}" step="1"> href="ListByPageServlet?curIndex=${p}">${p} c:forEach> href="ListByPageServlet?curIndex=${pages.curIndex==pages.totalPage?pages.totalPage:pages.curIndex+1}">下一页

使用JSTL需要导入相关包


 (部分jstl支持EL表达式)

    -----jsp中EL表达式:11个${}------
    1.pageScope
    2.requestScope
    3.sessonScope
    4.applicationScope
    5.Cookies
    ..........

你可能感兴趣的:(JSP 标准标签库(JSTL)中C标签的用法)