} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
}
Servlet层:DataServlet
package cn.csdn.customer.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.csdn.customer.dao.CustomerDao;
import cn.csdn.customer.dao.CustomerDaoImpl;
import cn.csdn.customer.domain.Customer;
public class DataServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private CustomerDao customerDao = new CustomerDaoImpl();
final static int count = 10;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/* 获取要显示当前页参数 */
int pages=Integer.parseInt(request.getParameter("pages"));
/* 查寻数据的起始点 */
int start =(pages-1)* count;
/* 查询要显示的数据 */
List<Customer> entities = customerDao.findAll(start,count);
/* 查询数据的条数 */
int sum=customerDao.getCount();
/* 查询数据的条数 */
int sumpages=(sum/count==0?sum/count:sum/count+1);
request.setAttribute("pages",pages);
request.setAttribute("entities", entities);