用JSTL實(shí)現(xiàn)的分頁 含
Posted on 2008-11-24 18:28 wesley1987 閱讀(533) 評論(0) 編輯 收藏 所屬分類: struts學(xué)習(xí)項(xiàng)目
純粹在JSP中實(shí)現(xiàn)的分頁,效果只有數(shù)據(jù)上一頁 下一頁的連接。
這種在JSP中取數(shù)據(jù)庫的做法已經(jīng)不推薦了,但是可以作為在頁面顯示數(shù)據(jù) 和學(xué)習(xí)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>當(dāng)前第${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>當(dāng)前第${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>