• [织梦吧]唯一域名:www.dedecms8.com,织梦DedeCMS学习平台.

织梦吧 - dedecms,网站模板,建站教程,图片素材免费下载

当前位置: 织梦吧 > 编程与数据库 > Jsp编程 >

自定义数据分页示例(10)

来源: www.dedecms8.com 编辑:织梦吧 时间:2012-06-28点击:

  } 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);

About D8

  • ©2014 织梦吧(d8) DedeCMS学习交流平台
  • 唯一网址 www.DedeCMS8.com 网站地图
  • 联系我们 tom@tiptop.cn ,  QQ