<%-- JSP全站自动生成HTML下载新闻系统 V3.1 作者:JSP天空网站长 曹进 QQ:173241393 --%> 实现jsp页面得分页显示功能方案
 
用户名:
密码:
终身会员
  首页 网络文摘 技术专题 下载中心 JSP培训 公司产品 JSP虚拟主机 技术论坛 会员 JSP免费空间  
  技术文摘: JSP基础 | JSP高级 | JSP环境 | JAVA基础 | JAVA高级 | JAVA工具 | JAVA数据库 | WEB框架 | XML相关 | JAVA考试 | J2EE相关 | J2ME相关 |
  视频下载: 程序设计数据库相关教程计算机基础教程图形图像网络技术网络安全时空书库EasyShop虚拟主机JSP培训技术论坛
  书籍教程: JSP教程Java教程图像软件XML教程数据库教程网页教程工具软件服务器相关ASP教程PHP教程CGI教程.NET教程
  代码下载: ASP代码下载JSP代码下载PHP代码下载CGI代码下载Flash代码C/C++/VCPowerBuilderDelphiVisualBasicVisualFoxpro
您的位置: 首页 -> 文章分类 -> JSP高级 -> 实现jsp页面得分页显示功能方案
 文摘搜索
 
 文摘资源分类
 
 文摘总排行榜TOP10
 
 最新更新文摘TOP10
 

实现jsp页面得分页显示功能方案

[来源]管理员   [作者]网络文摘   [时间]2007-04-11
推荐等级: 点击:

//接口的定义:

public interface ContactBean {

 public int getAvailableCount()throws Exception;

 public int getAvailableCount(int id)throws Exception;

 public PageBean listData(String page)throws Exception ;

 public PageBean listData(String page,int id)throws Exception ;

 public Collection getResult()throws Exception;

}

//pageBean的定义:

public class PageBean {

 public int curPage;//当前的页值。

 public int maxPage;//最大的页数。

 public int maxRowCount;//最大的行数。

 public static int rowsPerPage=10; //控制分页的行数。

 public java.util.Collection data; //所要显示的数据的集合。

 public PageBean() {

 }

 public void countMaxPage(){

  if(this.maxRowCount%this.rowsPerPage==0){

   this.maxPage=this.maxRowCount/this.rowsPerPage;

  }else{

   this.maxPage=this.maxRowCount/this.rowsPerPage+1;

  }

 }

 public Collection getResult(){

  return this.data;

 }

 public PageBean(ContactAdapter bean,int id)throws Exception{

  this.maxRowCount=bean.getAvailableCount(id);

  if(maxRowCount==0)

   maxRowCount=1;

  System.out.println(maxRowCount);

  this.data=bean.getResult();

  this.countMaxPage();

 }

 public PageBean(ContactAdapter bean)throws Exception{

  this.maxRowCount=bean.getAvailableCount();

  this.data=bean.getResult();

  this.countMaxPage();

 }

}

//对ContactBean接口进行adapter模式的封装。方便实用。

public class ContactAdapter implements ContactBean{

 public ContactAdapter() { }

 public int getAvailableCount()throws Exception{

  return 0;

 }

 public int getAvailableCount(int id)throws Exception{

  return 0;

 }

 public PageBean listData(String page)throws Exception {

  return null;

 }

 public PageBean listData(String page,int id)throws Exception {

  return null;

 }

 public Collection getResult()throws Exception{

  return null;

 }

}

在使用中你可以实现com.cn.interfaces.ContactBean 或继承 com.cn.interfaces.ContactAdapter都可以。

实现方法:

              实现一:其中不需要键入任何参数。

public int getAvailableCount()throws Exception;

               public PageBean listData(String page)throws Exception ;

               public Collection getResult()throws Exception;

              实现二:需要键入参数。

public int getAvailableCount(int id)throws Exception;

               public PageBean listData(String page,int id)throws Exception ;

public Collection getResult()throws Exception;

例如:

Public class TestContact extends ContactAdapter{

    Private Collection data;

    Public int getAvailableCount(int unitID) throws Exception{       

       BSIResultSet rs = new DBUtil().getResult(“

select count(*) NUM from TableTest where unit_id ="+id);

       return rs.getInt(NUM);

}

public PageBean listData(String page,int incept_sort_id)throws Exception {

  PageBean p = new PageBean(this,incept_sort_id);

  int pageNum = Integer.parseInt(page);

  BSIResultSet rs = con.getResult(

sql, ( pageNum -1)* p.rowsPerPage,, pageNum*p.rowsPerPage );

  p.curPage = pageNum;

  p.data = this.getTestBean(rs);

//此方法是把查询的数据封装在一个collection中。

  return p;

}

public Collection getResult()throws Exception{

    return this.data;

}

}

其中testBean是封装好的数据bean。

如果没有参数的话。可以使用没有参数的一组接口。

例如:在jsp中如何是用借口 。

//属性使用。业务逻辑。
//显示分页的表单。

加入javaScript的page.js.在jsp页面上加入:

  

[收藏][打印][关闭]
在线咨询服务 在线咨询服务 在线咨询服务 在线咨询服务
Copyright©2005-2006陕西思远数码科技有限责任公司 服务电话:029-88212987 传真:029-88278265 售后服务QQ:173241393
地址:陕西省西安市吉祥路186号太白新苑C座2104 陕ICP备05004508号