java web分页错误
package stuServlet;import
import
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import stuentDao.stuDao;
public class stuPages extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int countPerPage = 5;
HttpSession session = request.getSession();
String pageIndex = request.getParameter("pageIndex");// 默认第一页
if (pageIndex == null) {
pageIndex = "1";
}
// 首次访问,查询所有数据,计算页数。
ArrayList list = (ArrayList) session.getAttribute("list");
if (list == null) {
stuDao studentDao = new stuDao();
list = studentDao.queryAllStudents();
session.setAttribute("list", list);
int pageCount;
if (list.size() % countPerPage == 0) {
pageCount = list.size() / countPerPage;
} else {
pageCount = list.size() / countPerPage + 1;
}
session.setAttribute("pageCount", pageCount);
session.setAttribute("studentCount", list.size());
}
// 根据当前页数在查询集合中获取数据
int currentPageIndex = Integer.parseInt(pageIndex);
ArrayList pageStudents = new ArrayList();
for (int i = 0; i < list.size(); i++) {
if (i >= (currentPageIndex - 1) * countPerPage
&& i < (currentPageIndex) * countPerPage) {
pageStudents.add(list.get(i));
}
}
session.setAttribute("pageStudents", pageStudents);
session.setAttribute("currentPageIndex", currentPageIndex);
RequestDispatcher rd = request
.getRequestDispatcher("/showStudents1.jsp");
rd.forward(request, response);
}
}
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.
<html>
<body>
<b>以下是学生信息</b>
<hr>
共${studentCount}条记录; 共${pageCount}页; 当前第 ${currentPageIndex}页;
<table>
<tr bgcolor="yellow">
<td>学号</td>
<td>姓名</td>
<td>性别</td>
</tr>
<c:forEach items="${pageStudents}" var="stu">
<tr bgcolor="pink">
<td>${stu.stuno}</td>
<td>${stu.stuname}</td>
<td>${stu.stusex}</td>
</tr>
</c:forEach>
</table>
<a href="/fenfe/stuServlet/stuPages?pageIndex=1">首页</a>
<c:if test="${currentPageIndex!=1 }">
<a href="/fenfe/stuServlet/stuPages?pageIndex=${currentPageIndex-1 }">上一页</a>
</c:if>
<c:if test="${currentPageIndex!=pageCount }">
<a href="/fenfe/stuServlet/stuPages?pageIndex=${currentPageIndex+1}">下一页</a>
</c:if>
<a href="/fenfe/stuServlet/stuPages?pageIndex=${pageCount}">尾页</a>
</body>
</html>
[local]1[/local]
数据库中学生数据显示不出来,记录,几页没数据,求大神指导一下。