昨晚才完成的可能有BUG也给你点提示
page_record(每页显示多少个记录)
page_action(分页数控中显示多少个)
OffSet(当前第页)
调用广东:GetPageList(4,5,page)
http://localhost:8081/job/case.go?OffSet=3JSP中调用
jsp返回offset的记录传到变量xdd得到当前页
<%
ArrayList al = Scase.GetPageList(2,3,xdd);
Iterator it = al.iterator();
while(it.hasNext()){
String itStr = (String)it.next();
out.print(itStr);
}%>
public int GetCount(){
try{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
conn = getConnection(dbUrl,dbUser,dbPwd);
String sql = "select count(*) from 数据库"
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
if(rs.next())
return CstrInt(rs.getString(1));
return JObCount;
}catch(Exception e){return 0;}
}
public ArrayList GetPageList(int page_record,int page_action,int OffSet){
try{
int Page_first = 1;
int C = GetCount();//取总记录数
int o = C % page_record;
int i = C / page_record;
if(o == 1) i++;//计算一共分i页
int Count = i;
for(int qint = 0; OffSet > qint; qint += page_action)//计算数控第几开始如<<1 2 3 4 5 6>>中的1
Page_first = qint + 1;
int GO;
GO = Page_first + page_action - 1;
if(i >= GO)//如果总记录大于或者等于数控最后一个数如上面的6
i = GO;
ArrayList List = new ArrayList(); for(int x = Page_first ; x <= i ; x++)
{
String Str = ""+x+"";//组成式样
if(x == OffSet)
Str = " <font color=\"#FF0000\">"+Str+"</font> ";
else
Str = " <a href=\"case.go?OffSet="+x+"\">"+Str+"</a> ";
if(x == 1)
Str = "<<" + Str;
if(x == i && (i != GO || Count == x))
Str = Str+">>";
if(x == i && i == GO && Count !=x)
Str = Str + " <a href=\"case.go?OffSet="+ (x+1) +"\" title=\"上移动到"+(x+1)+"页\"><strong>>></strong></a> ";
if(x == Page_first && x != 1)
Str = " <a href=\"case.go?OffSet="+ (x-1) +"\" title=\"下移到第"+(x-1)+"页\"><strong><<</strong></a> " + Str;
List.add(Str);
} return List;
}catch(Exception e){return null;}
}
page_record(每页显示多少个记录)
page_action(分页数控中显示多少个)
OffSet(当前第页)
调用广东:GetPageList(4,5,page)
http://localhost:8081/job/case.go?OffSet=3JSP中调用
jsp返回offset的记录传到变量xdd得到当前页
<%
ArrayList al = Scase.GetPageList(2,3,xdd);
Iterator it = al.iterator();
while(it.hasNext()){
String itStr = (String)it.next();
out.print(itStr);
}%>
public int GetCount(){
try{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
conn = getConnection(dbUrl,dbUser,dbPwd);
String sql = "select count(*) from 数据库"
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
if(rs.next())
return CstrInt(rs.getString(1));
return JObCount;
}catch(Exception e){return 0;}
}
public ArrayList GetPageList(int page_record,int page_action,int OffSet){
try{
int Page_first = 1;
int C = GetCount();//取总记录数
int o = C % page_record;
int i = C / page_record;
if(o == 1) i++;//计算一共分i页
int Count = i;
for(int qint = 0; OffSet > qint; qint += page_action)//计算数控第几开始如<<1 2 3 4 5 6>>中的1
Page_first = qint + 1;
int GO;
GO = Page_first + page_action - 1;
if(i >= GO)//如果总记录大于或者等于数控最后一个数如上面的6
i = GO;
ArrayList List = new ArrayList(); for(int x = Page_first ; x <= i ; x++)
{
String Str = ""+x+"";//组成式样
if(x == OffSet)
Str = " <font color=\"#FF0000\">"+Str+"</font> ";
else
Str = " <a href=\"case.go?OffSet="+x+"\">"+Str+"</a> ";
if(x == 1)
Str = "<<" + Str;
if(x == i && (i != GO || Count == x))
Str = Str+">>";
if(x == i && i == GO && Count !=x)
Str = Str + " <a href=\"case.go?OffSet="+ (x+1) +"\" title=\"上移动到"+(x+1)+"页\"><strong>>></strong></a> ";
if(x == Page_first && x != 1)
Str = " <a href=\"case.go?OffSet="+ (x-1) +"\" title=\"下移到第"+(x-1)+"页\"><strong><<</strong></a> " + Str;
List.add(Str);
} return List;
}catch(Exception e){return null;}
}
try{
Integer Cint=new Integer(Integer.parseInt(atgs));
int xdd = Cint.intValue();
return xdd;
}catch(Exception e){return 0;}
}
如果用上面朋友的方法,那么我上面的程序中的分页就没有办法用了。
jsp 显示
对每个12345,加超连接,
如果是后一部分,那么List=678910,
就是一个普通分页,对12345加一个溢出处理就可以了把?
int i = C / page_record;
if(o == 1) i++;//计算一共分i页
int Count = i;有BUG已经修正:
int o = C % page_record;
int i = C / page_record;
if(o >= 1) i++;//计算一共分i页
int Count = i;