//使用分页 //1.计算总页数, StudentBizImpl bb = new StudentBizImpl(); int pageSize = 5;//每页显示记录数 int count = bb.getStudentCount();//总记录数计算总页数 int totalpages= (count%pageSize ==0)?(count/pageSize):(count/pageSize+1); //获取当前页 String currentPage = request.getParameter("pageIndex"); if(currentPage==null){ currentPage = "1"; } int pageIndex = Integer.parseInt(currentPage);//强转为int,便于计算 //计算开始索引 if(pageIndex < 1){ pageIndex = 1; }else if(pageIndex > totalpages){ pageIndex = totalpages; } int stateIndex = pageSize*(pageIndex-1)+1; //结束 int endIndex = pageSize*pageIndex; String search =""; if(request.getParameter("search")!=null){ search = request.getParameter("search"); } List<Student> studentList = bb.getList(stateIndex,endIndex); request.setAttribute("studentList",studentList); request.setAttribute("pageIndex",pageIndex); request.setAttribute("totalpages",totalpages); request.getRequestDispatcher("studentList.jsp").forward(request,response);