Posted on 2008-11-24 18:28
wesley1987 阅读(524)
评论(0) 编辑 收藏 所属分类:
struts学习项目
纯粹在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>