一个通用的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
补充:Web开发 , Jsp ,