您的位置:首页 > Web前端 > JavaScript

JSP分页程序

2006-08-02 21:34 232 查看
 

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'>/u603B/u8BA1<font color='red'>" + getCountTopic() + "</font>/u6761/u8BB0/u5F55," + "/u3010/u5171<font  color='red'>" + getPageCount() + "</font>/u9875/u3011";
        s = s + "/u3010" + intPageSize + "/u6761//u9875/u3011 /u5F53/u524D/u7B2C<font color='red'>" + getIntPage() + "</font>/u9875(/u5217/u51FA/u7B2C" + k + "/u5230/u7B2C" + getIntPage() * intPageSize + "/u6761)     ";
        if(intPage > 1)
            s = s + " <A href=" + HttpFile + "?pages=1" + str_parameter + ">/u9996/u9875</A> ";
        else
            s = s + " /u9996/u9875 ";
        if(intPage > 1)
            s = s + " <A href=" + HttpFile + "?pages=" + i + str_parameter + ">/u4E0A/u4E00/u9875</A> ";
        else
            s = s + " /u4E0A/u4E00/u9875 ";
        if(intPage < intPageCount)
            s = s + " <A href=" + HttpFile + "?pages=" + j + str_parameter + ">/u4E0B/u4E00/u9875</A> ";
        else
            s = s + " /u4E0B/u4E00/u9875 ";
        if(intPageCount > 1 && intPage != intPageCount)
            s = s + " <A href=" + HttpFile + "?pages=" + intPageCount + str_parameter + ">/u5C3E/u9875</A>";
        else
            s = s + " /u5C3E/u9875</font>";
        s = s + "</form>";
        return s;
    }
   
4000
public void closeConn()
    {
        db.close();
    }
}
  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息