昨晚才完成的可能有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 = "&lt;&lt;" + Str;
     
if(x == i && (i != GO || Count == x))
Str = Str+"&gt;&gt;";
 
if(x == i && i == GO && Count !=x)
Str = Str + " <a href=\"case.go?OffSet="+ (x+1) +"\" title=\"上移动到"+(x+1)+"页\"><strong>&gt;&gt;</strong></a> ";
 
if(x == Page_first && x != 1)
Str = " <a href=\"case.go?OffSet="+ (x-1) +"\" title=\"下移到第"+(x-1)+"页\"><strong>&lt;&lt;</strong></a> " + Str;

List.add(Str);
   } return List;
  
}catch(Exception e){return null;}
}

解决方案 »

  1.   

    public int CstrInt(String atgs){
            try{      
                Integer Cint=new Integer(Integer.parseInt(atgs));
                int xdd = Cint.intValue();
    return xdd;
    }catch(Exception e){return 0;}
    }
      

  2.   

    这个方法是干什么用的呀。如何来使用。GetPageList
    如果用上面朋友的方法,那么我上面的程序中的分页就没有办法用了。
      

  3.   

    return list 123456,
    jsp 显示
    对每个12345,加超连接,
    如果是后一部分,那么List=678910,
    就是一个普通分页,对12345加一个溢出处理就可以了把?
      

  4.   

    那看你的分页是怎做了!我的分页只需要程序返回Offset这个变量就能分页成功了,GetPageList这个是一个bean中的函数,只要向GetPageList(每页多少记录,<<123456>>每页显示个数,当前页的记录Offset),就能返回一组数组,数组就是存放每个 1 2 3 的HTML代码,当然也可以像你想使用的(如点击<<时,显后6到10页.)效果,那么你是怎分页的?改改就可以用了!!
      

  5.   

    int o = C % page_record;
    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;