实现jsp页面得分页显示功能方案
来源:互联网 发布:逐鹿seo军刀破解版 编辑:程序博客网 时间:2024/05/17 21:43
com.cn.page.PageBean.java 用于控制分页的情况和数据的处理的。
com.cn.page.PageView.java 用于在jsp页面中显示表单的。
//接口的定义:
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中如何是用借口。
<jsp:useBean id="pageCtl" class="com.cn.page.PageBean" scope="request"/>
<%
Vector c=(Vector)pageCtl.getResult();
Iterator it=c.iterator();
while(it.hasNext()){
TestBean d=(TestBean)it.next();//的到每一个单独的数据。
//可以取出此bean的属性值。
%>
。。。。。//属性使用。业务逻辑。
<form action="test.do" method="post" name="PageForm">
<%out.print(ViewPage.getView(pageCtl));%>
</form>
//显示分页的表单。
加入javaScript的page.js.在jsp页面上加入:
<script language="JavaScript" src="js/page.js">即可。
function jumping(){
document.PageForm.submit();
return;
}
function gotoPage(Pagenum){
document.PageForm.jumpPage.value=Pagenum;
document.PageForm.submit();
return;
}
- 实现jsp页面得分页显示功能方案
- 实现jsp页面得分页显示功能方案
- JSP页面实现分页功能
- jsp实现分页和页面跳转功能
- jsp实现分页显示的功能
- jsp实现分页(限定显示指定页数)和页面跳转功能
- JSP实现分页功能
- JSP实现分页功能
- JSP实现分页功能
- JSP实现分页功能
- JSP实现分页功能
- Jsp实现分页功能
- jsp实现分页功能
- jsp页面实现分页
- jsp实现页面分页。
- JSP实现分页显示
- JSP页面分页显示数据
- JSP页面分页显示数据
- 建立基于JDBC的resin3.0.8的连接池
- 基于Cocoon的应用(二)及系统权限探讨
- 偶的java日期选择器
- Step-by-Step搭建Linux下的java开发环境
- Modify Your Codes with PMD(1)
- 实现jsp页面得分页显示功能方案
- CheckStyle使用详解
- java中的类型转换
- JGraph 常见问题解答(续二)
- Java学习资源推荐(书籍和网站)
- new StringBuffer(int n)的陷阱
- 如何建立一个带登陆页面的Struts数据库应用程序
- Log4j的中文文档
- log4j的FAQ