`
jordan_micle
  • 浏览: 240258 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

JSTL实现分页

阅读更多

最多显示左右三页间隔,首页和末页必显示
1页 
当前任意页  1
2页 
当前任意页  1 2
3页 
当前任意页  1 2 3
4页 
当前任意页  1 2 3 4
5页 
当前任意页  1 2 3 4 5
6页 
当前第1页  1 2 3 4 ... 6
当前第2-5页 1 2 3 4 5 6
当前第6页  1 ... 3 4 5 6
7页 
当前第1页  1 2 3 4 ... 7
当前第2页  1 2 3 4 5 ... 7
当前第3-5页 1 2 3 4 5 6 7
当前第6页  1 ...  3 4 5 6 7
当前第7页  1 ... 4 5 6 7
8页
当前第1页  1 2 3 4 ... 8
当前第2页  1 2 3 4 5 ... 8
当前第3页  1 2 3 4 5 6 ... 8
当前第4-5页 1 2 3 4 5 6 7 8
当前第6页  1 ... 3 4 5 6 7 8
当前第7页  1 ... 4 5 6 7 8
当前第8页  1 ... 5 6 7 8
9页
当前第1页  1 2 3 4 ... 9
当前第2页  1 2 3 4 5 ... 9
当前第3页  1 2 3 4 5 6 ... 9
当前第4页  1 2 3 4 5 6 7 ... 9
当前第5页  1 2 3 4 5 6 7 8 9
当前第6页  1 ... 3 4 5 6 7 8 9
当前第7页  1 ... 4 5 6 7 8 9
当前第8页  1 ... 5 6 7 8 9
当前第9页  1 ... 6 7 8 9
10页

当前第1页  1 2 3 4 ... 10
当前第2页  1 2 3 4 5 ... 10
当前第3页  1 2 3 4 5 6 ... 10
当前第4页  1 2 3 4 5 6 7 ... 10
当前第5页  1 2 3 4 5 6 7 8 ... 10
当前第6页  1 ... 3 4 5 6 7 8 9 10
当前第7页  1 ... 4 5 6 7 8 9 10
当前第8页  1 ... 5 6 7 8 9 10
当前第9页  1 ... 6 7 8 9 10
当前第10页 1 ... 7 8 9 10
11页
当前第1页  1 2 3 4 ... 11
当前第2页  1 2 3 4 5 ... 11
当前第3页  1 2 3 4 5 6 ... 11
当前第4页  1 2 3 4 5 6 7 ... 11
当前第5页  1 2 3 4 5 6 7 8 ... 11
当前第6页  1 ... 3 4 5 6 7 8 9 ... 11
当前第7页  1 ... 4 5 6 7 8 9 10 11
当前第8页  1 ... 5 6 7 8 9 10 11
当前第9页  1 ... 6 7 8 9 10 11
当前第10页 1 ... 7 8 9 10 11
当前第11页 1 ... 8 9 10 11
12页
当前第1页  1 2 3 4 ... 12
当前第2页  1 2 3 4 5 ... 12
当前第3页  1 2 3 4 5 6 ... 12
当前第4页  1 2 3 4 5 6 7 ... 12
当前第5页  1 2 3 4 5 6 7 8 ... 12
当前第6页  1 ... 3 4 5 6 7 8 9 ... 12
当前第7页  1 ... 4 5 6 7 8 9 10 ... 12
当前第8页  1 ... 5 6 7 8 9 10 11 12
当前第9页  1 ... 6 7 8 9 10 11 12
当前第10页 1 ... 7 8 9 10 11 12
当前第11页 1 ... 8 9 10 11 12
当前第12页 1 ... 9 10 11 12

 

实现方案:
总页数pageAmount
当前页码currentPage
页数左间隔/右间隔interval
(1)第一页和最后一页肯定显示n=pageAmount,当n=1时只显示1页
(2)中间页码显示
如果currentPage<=5,从2显示至currentPage
如果currentPage>5,显示省略号,然后从currentPage-3显示至currentPage
如果currentPage<=pageAmount-4或者pageAmount-4<=0,从currentPage+1显示至pageAmount
如果currentPage>pageAmount-4,从currentPage+1显示至currentPage+3,然后显示省略号和pageAmount

 

每页显示&nbsp;${sessionScope.count}&nbsp;条记录&nbsp;
总记录数/总页数&nbsp;${sessionScope.recordAmount}/${sessionScope.pageAmount}
&nbsp;当前第&nbsp;
<a href="ViewServlet?currentPage=1">[1]</a>&nbsp;
<c:if test="${sessionScope.pageAmount!=1}">
	<c:choose>
		<c:when test="${requestScope.currentPage<=5}">
			<c:forEach var="i" begin="2" end="${requestScope.currentPage}">
				<a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp;
			</c:forEach>
		</c:when>
		<c:otherwise>
			...&nbsp;
			<c:forEach var="i" begin="${requestScope.currentPage-3}"
				end="${requestScope.currentPage}">
				<a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp;
			</c:forEach>
		</c:otherwise>
	</c:choose>
	<c:choose>
		<c:when test="${requestScope.currentPage>=sessionScope.pageAmount-4 
			|| sessionScope.pageAmount-4<=0}">
			<c:forEach var="i" begin="${requestScope.currentPage+1}"
				end="${sessionScope.pageAmount}">
				<a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp;
			</c:forEach>
		</c:when>
		<c:otherwise>
			<c:forEach var="i" begin="${requestScope.currentPage+1}"
				end="${requestScope.currentPage+3}">
				<a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp;
			</c:forEach>
			...&nbsp;
			<a href="ViewServlet?currentPage=${sessionScope.pageAmount}">
				[${sessionScope.pageAmount}]</a>&nbsp;
		</c:otherwise>
	</c:choose>
</c:if>
页

  

 

分享到:
评论
1 楼 bluky999 2010-08-04  
你这个有个小不足,就是currentpage仍然有链接 哈哈

  需要加一句

相关推荐

Global site tag (gtag.js) - Google Analytics