您的位置:首页 > Web前端 > JavaScript

JSP分页

2013-12-12 21:50 651 查看
<form action="" id="form" method="post" >
<table border="0" width="750px" style="margin-left: 110px;margin-top: 110px;">
<tr bgcolor="#FF6A6A" height="30px">
<th align="center">
<input type="checkbox"  onclick="selectAll(this)"/> <span>全选</span>
</th>
<th>
用户id
</th>
<th>
朋友id
</th>
<th>
用户关系
</th>
<th>
修改分组
</th>
</tr>
<c:set var="pageCount" value="4"/><!-- 每页显示的记录数 -->
<c:set var="totalCount" value="${fn:length(relationListFull)}"/><!-- 总记录数 -->
<c:set var="totalPage" value="0"/>
<c:set var="index" value="${index}"/><!--判断index是否为null -->
<c:if test="${index == null}">
<c:set var="index" value="1"/>
</c:if>
<c:set var="start" value="${(index-1)*pageCount}"/><!--开始遍历的下标 -->
<c:set var="end" value="${start+3}"/><!--结束的下标-->
<c:if test="${end>=totalCount}">
<c:set var="end" value="${totalCount}"/>
</c:if>
<!-- 判断总的页数,用总记录数除以每页显示的条数,如果不等于0要加1 -->
<c:choose>
<c:when test="${totalCount div pageCount == 0}">
<c:set var="totalPage" value="${totalCount div pageCount}"/>
<fmt:formatNumber var="totalPage" type="number" value="${totalPage}" maxFractionDigits="0"></fmt:formatNumber>
</c:when>
<c:otherwise>
<!--如果不为0,则对计算出的结果格式化,取小数的第一个数字 -->
<fmt:formatNumber var="totalPage" type="number" value="${(totalCount div pageCount)+1}" maxFractionDigits="0"></fmt:formatNumber>
</c:otherwise>
</c:choose>
<!--遍历List-->
<c:set var="i" value="0"></c:set>
<c:forEach var="relation" begin="${start}" items="${relationListFull}" end="${end}" step="1">
<tr bgcolor="#F2F2F2" height="30px">
<td>
<input type="checkbox"  value="" />
</td>
<td align="center">
${relation.userId}
</td>
<td align="center">
${relation.friendId}
</td>
<td align="center">
${relation.relation}
</td>
<td align="center">
<input type="image" src="images/altgroups.jpg" onclick="forward(${i})"/>
</td>
<c:set var="i" value="${i+1}"></c:set>
</tr>
</c:forEach>
<tr>
<td colspan="6">
当前第
${index}
页  共
${totalPage}
页
<c:if test="${index > 1}">
<a href="forward?index=${index - 1}&type=makePage" style="text-decoration:none;"> 上一页</a>
</c:if>

<c:if test="${index < totalPage}">
<a href="forward?index=${index + 1}&type=makePage" style="text-decoration:none;"> 下一页</a>
</c:if>

<a href="forward?index=1&type=makePage" style="text-decoration:none;">首页</a>
<a href="forward?index=${totalPage}&type=makePage" style="text-decoration:none;">末页</a>
</td>
</tr>
</table>
</form>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: