hays

海纳百川
posts - 25, comments - 48, trackbacks - 0, articles - 0
  BlogJava :: 首页 ::  :: 联系 :: 聚合  :: 管理

页面分页函数

Posted on 2006-10-30 15:49 hays(海纳百川) 阅读(232) 评论(0)  编辑  收藏

 

package  com.vitamin.download;
import  javax.servlet. * ;
import  javax.servlet.http. * ;
import  java.math. * ;
import  java.sql. * ;

public   class  Pagination 
{
    
    
private  String strPage  =   null ;
    
private   int  curPage; // 当前页;
     private   int  m_rows; // 每页包括的几个数据项;
     private   int  totalPage; // 总页数
    
    
public  Pagination()
    
{
        
    }

    
    
public   int  getRows()
    
{
        
return   this .m_rows;
    }

    
    
public  Pagination( int  rows)
    
{
        
this .setRows(rows);
    }

    
    
public  String getstrPage(HttpServletRequest request,String page)
    
{
        
try
        
{
                strPage 
=  request.getParameter(page);
        }

        
catch (Exception e)
        
{
                System.out.print(e.getMessage());
        }

        
return  strPage;
    }

    
    
public   int  getcurPage(String strPage)
    
{
        
try
        
{
            
if (strPage == null )
            
{
                
this .curPage  = 1 ;
            }

            
else
            
{
                
this .curPage  =  Integer.parseInt(strPage);
                
if ( this .curPage < 1 )
                
{
                    
this .curPage  = 1 ;
                }

            }

            
        }

        
catch (Exception e)
        
{
            System.out.print(
" curPages " );
        }

        
return   this .curPage;
    }

    
     
public   void  setRows( int  rows)
     
{
           m_rows
= rows;
     }

       
//  取得页数
      
     
public   int  getTotalPages( int  rowcounts)
     
{
           
int  test; //  变量
           test = rowcounts % m_rows; //  取得余数
            if (test == 0 )
           
{
               totalPage 
=  rowcounts / m_rows; //  可以整除,总页数;
           }

           
else
           
{
               totalPage
= rowcounts / m_rows + 1 ; //  不是的话就加一  
           }

           
return  totalPage; //  返回页数
      }

       
//  结果集的返回
       
     
public  ResultSet getPageSet(ResultSet rs, int  curPages)
     
{
           
if (curPages == 1 )
           
{
              
               
return  rs; //  如果就只有一页
           }

           
else
           
{
               
int  i = 1 ;
               
try
               
{
                   
while (rs.next()) // 使rs跳到(curPages-1)*m_rows 那行;
                    {
                       i
= i + 1 ;
                       
if (i > ((curPages - 1 ) * m_rows))
                       
{
                           
break ; //  退出
                       }

                   }

                   
return  rs; //  从退出开始将结果集返回
               }

               
catch (Exception e)
               
{
                   System.out.print(e.getMessage());
               }

           }

           
return  rs;
       }



}


只有注册用户登录后才能发表评论。


网站导航: