一个通用的JSP分页程序
//本程序使用了一个类反射的类,可以自动将查询出来的值填充到值对象里。
//这个类可以参见ibm的文章:使用类反射机制简化struts的开发.
package com.lyjweb.wyhn.common;
import java.sql.*;
import com.lyjweb.common.*;
import java.util.*;
public class fenye {
private connection con=null;
private string sql="";
private string page="1";// 当前页
private int i_page=1;//当前页
private int i_page_count=10;//每页显示条数
private string nextpage,prepage,sumpage,sumcount;
private string sql_select,sql_from,sql_where,sql_order;
private string sql_pre="";
private string sql_count=""; //count(*)语句
private resultset rst=null;
private preparedstatement stm=null;
private collection result_c=null;
private string s_null="无";
///////////////////////////输入值///////////////////////////////
public void setconnection(connection con)
{
this.con=con;
}
public void setsql(string sql_select,string sql_from,string sql_where,string sql_order)
{
//this.sql=sql;
this.sql_select=sql_select;
this.sql_from=sql_from;
this.sql_where=sql_where;
this.sql_order=sql_order;
this.sql_count="select count(*) " + sql_from + " " + sql_where;
this.sql=sql_select + " " + sql_from + " " + sql_where + " " + sql_order;
}
public void setstm(preparedstatement stm)
{
this.stm=stm;
}
public void setpage(string p)
{
if(p==null)
{
this.page="1";
this.i_page=1;
}
else
{
p=p.trim();
if(p.equals("")) p="1";
this.page=p;
this.i_page=integer.parseint(this.page);
}
}
public void setpagecount(int pcount)
{
this.i_page_count=pcount;
}
public void setsqlpre(string sqlpre)
{
this.sql_pre=sqlpre;
}
public void sets_null(string s_null)
{
this.s_null=s_null;
}
//////////////////////////////////////返回值///////////////////////////////////////////
public resultset getrst()
{
return rst;
}
public string getpage()
{
return page;
}
public string getnextpage()
{
return nextpage;
}
public string getprepage()
{
return prepage;
}
public string getsumpage()
{
return sumpage;
}
public string getcount()
{
return sumcount;
}
public collection getcollection()
{
return result_c;
}
////////////////////////////////////////操 作///////////////////////////////////////////////
private string b_string,f_string;
private string comsql;
private void countpage() throws exception
上一篇: 有关js隐藏错误的代码实例