JSP分页程序

 

JSP分页程序

                                           ---摘自书本实例

package  com.zh.util;

import  com.zh.conpool.Condata;
import  java.sql.ResultSet;
import  java.sql.SQLException;

public   class  page
{

    ResultSet rs;
    ResultSet rst;
    
private int intCountTopic;
    
public int intPageSize;
    
public int intPageCount;
    
public int intPage;
    
private String Countsql;
    
private String Pagisql;
    
private String str;
    
private String str_where;
    
private String str_parameter;
    
private String nowPage;
    
private String HttpFile;
    Condata db;

    
public page()
    
{
        rs 
= null;
        rst 
= null;
        intCountTopic 
= 0;
        intPage 
= 0;
        Countsql 
= null;
        Pagisql 
= null;
        str 
= null;
        str_where 
= null;
        str_parameter 
= "";
        db 
= new Condata();
    }


    
public static void main(String args[])
    
{
     
    }


    
public void setPages(int i)
    
{
        intPageSize 
= i;
    }


    
public String getPagisql()
    
{
        
return Pagisql;
    }


    
public ResultSet setQuerysql(String s, String s1, String s2, String s3)
        
throws SQLException
    
{
        ResultSet resultset 
= null;
        nowPage 
= s3;
        HttpFile 
= s2;
        Countsql 
= "select count(*) from " + s + " " + s1;
        Pagisql 
= "select * from " + s + " " + s1 + " order by id desc";
        
try
        
{
            Condata _tmp 
= db;
            Condata.getConnection();
        }

        
catch(Exception exception)
        
{
            exception.getMessage();
        }

        
try
        
{
            resultset 
= querySql(Countsql, Pagisql);
        }

        
catch(SQLException sqlexception)
        
{
            sqlexception.getMessage();
        }

        
return resultset;
    }


    
public ResultSet querySql(String s, String s1)
        
throws SQLException
    
{
        
try
        
{
            Condata condata 
= db;
            Condata.getConnection();
        }

        
catch(Exception exception) { }
        
if(nowPage == null)
        
{
            intPage 
= 1;
        }
 else
        
{
            intPage 
= Integer.parseInt(nowPage);
            
if(intPage < 1)
                intPage 
= 1;
        }

        rs 
= db.executeQuery(s);
        
if(rs.next())
            intCountTopic 
= rs.getInt(1);
        intPageCount 
= intCountTopic % intPageSize == 0 ? intCountTopic / intPageSize : intCountTopic / intPageSize + 1;
        
if(intPage > intPageCount)
            intPage 
= intPageCount;
        rs.close();
        rst 
= db.executeQuery(s1);
        
return rst;
    }


    
public int getCountTopic()
    
{
        
return intCountTopic;
    }


    
public int getPageCount()
    
{
        
return intPageCount;
    }


    
public int getIntPage()
    
{
        
return intPage;
    }


    
public String PageFooter()
    
{
        String s 
= "<form action=" + HttpFile + " name=form1 methord=post>";
        
int i = intPage - 1;
        
int j = intPage + 1;
        
int k = (intPageSize * getIntPage() + 1- intPageSize;
        
if(k < 0)
            k 
= 0;
        s 
= s + "<font style='font-size: 9pt'>总计<font color='red'>" + getCountTopic() + "</font>条记录," + "【共<font  color='red'>" + getPageCount() + "</font>页】";
        s 
= s + "" + intPageSize + "条/页】 当前第<font color='red'>" + getIntPage() + "</font>页(列出第" + k + "到第" + getIntPage() * intPageSize + "条) &nbsp; &nbsp; ";
        
if(intPage > 1)
            s 
= s + " <A href=" + HttpFile + "?pages=1" + str_parameter + ">首页</A> ";
        
else
            s 
= s + " 首页 ";
        
if(intPage > 1)
            s 
= s + " <A href=" + HttpFile + "?pages=" + i + str_parameter + ">上一页</A> ";
        
else
            s 
= s + " 上一页 ";
        
if(intPage < intPageCount)
            s 
= s + " <A href=" + HttpFile + "?pages=" + j + str_parameter + ">下一页</A> ";
        
else
            s 
= s + " 下一页 ";
        
if(intPageCount > 1 && intPage != intPageCount)
            s 
= s + " <A href=" + HttpFile + "?pages=" + intPageCount + str_parameter + ">尾页</A>";
        
else
            s 
= s + " 尾页</font>";
        s 
= s + "</form>";
        
return s;
    }


    
public void closeConn()
    
{
        db.close();
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值