純粹在JSP中實現的分頁,效果只有數據上一頁 下一頁的連接。
這種在JSP中取數據庫的做法已經不推薦了,但是可以作為在頁面顯示數據 和學習JSTL的參考
分頁
:<br/>
<table border="1">
<tr>
<sql:query var="articleCount" sql="select count(*) from article" dataSource="${sqlDS}"></sql:query>
<c:forEach items="${articleCount.rowsByIndex}" var="articlecount">
<c:set var="Count">${articlecount[0]}</c:set>
</c:forEach>
<td>共 ${Count}條</td>
<c:set var="pageSize">10</c:set>
<c:if test="${Count%pageSize==0}"><c:set var="page">${Count/pageSize}</c:set></c:if>
<c:if test="${Count%pageSize!=0}"><c:set var="page">${(Count-Count%pageSize)/pageSize+1}</c:set></c:if>
<fmt:formatNumber maxFractionDigits="0" var="pageCount">${page}</fmt:formatNumber>
<td>共${pageCount}頁</td>
<c:if test="${empty param.pageNo}"><c:set var="currentPage" value="1"></c:set></c:if>
<c:if test="${not empty param.pageNo}"><c:set var="currentPage">${param.pageNo}</c:set></c:if>
<td>當前第${currentPage} 頁</td>
<td>
<c:if test="${currentPage>1}">
<a href="front/index.jsp?pageNo=${currentPage-1}">上一頁</a>
</c:if>
<c:if test="${currentPage==1}">上一頁 </c:if>
<c:if test="${currentPage<pageCount}">
<a href="front/index.jsp?pageNo=${currentPage+1}">下一頁</a>
</c:if>
<c:if test="${currentPage==pageCount}">下一頁 </c:if>
</td>
</tr>
</table>
<table border="3">
<sql:query var="RS" dataSource="${sqlDS}"
sql="select * from article where rownum<=${pageSize} and id not in(select id from article where rownum<=${pageSize*(currentPage-1)} )"
></sql:query><tr>
<c:forEach items="${RS.rowsByIndex}" var="article">
<td>${article[1]}</td>
<td>${article[2]}</td>
<td>${article[4]}</td>
<td>${article[5]}</td>
<td>[<fmt:formatDate value="${article[6]}" pattern="yyyy'年'M'月'd'日'"/>]</td>
</c:forEach></tr>
</table>
<table border="1">
<tr>
<sql:query var="articleCount" sql="select count(*) from article" dataSource="${sqlDS}"></sql:query>
<c:forEach items="${articleCount.rowsByIndex}" var="articlecount">
<c:set var="Count">${articlecount[0]}</c:set>
</c:forEach>
<td>共 ${Count}條</td>
<c:set var="pageSize">10</c:set>
<c:if test="${Count%pageSize==0}"><c:set var="page">${Count/pageSize}</c:set></c:if>
<c:if test="${Count%pageSize!=0}"><c:set var="page">${(Count-Count%pageSize)/pageSize+1}</c:set></c:if>
<fmt:formatNumber maxFractionDigits="0" var="pageCount">${page}</fmt:formatNumber>
<td>共${pageCount}頁</td>
<c:if test="${empty param.pageNo}"><c:set var="currentPage" value="1"></c:set></c:if>
<c:if test="${not empty param.pageNo}"><c:set var="currentPage">${param.pageNo}</c:set></c:if>
<td>當前第${currentPage} 頁</td>
<td>
<c:if test="${currentPage>1}">
<a href="front/index.jsp?pageNo=${currentPage-1}">上一頁</a>
</c:if>
<c:if test="${currentPage==1}">上一頁 </c:if>
<c:if test="${currentPage<pageCount}">
<a href="front/index.jsp?pageNo=${currentPage+1}">下一頁</a>
</c:if>
<c:if test="${currentPage==pageCount}">下一頁 </c:if>
</td>
</tr>
</table>
<table border="3">
<sql:query var="RS" dataSource="${sqlDS}"
sql="select * from article where rownum<=${pageSize} and id not in(select id from article where rownum<=${pageSize*(currentPage-1)} )"
></sql:query><tr>
<c:forEach items="${RS.rowsByIndex}" var="article">
<td>${article[1]}</td>
<td>${article[2]}</td>
<td>${article[4]}</td>
<td>${article[5]}</td>
<td>[<fmt:formatDate value="${article[6]}" pattern="yyyy'年'M'月'd'日'"/>]</td>
</c:forEach></tr>
</table>