struts分页怎么实现

示例代码如下:  
   
  1.PageInfo类:定义分页信息。 
/******************program   begin**************************/    
    
  
package    test;   
  
import    java.io. * ;   
  
public     final     class    PaginationInfo   
          
implements    Serializable    {   
      
/**页大小描述每页有多少行*/   
      
private   int   pageSize   =   20;   
      
/**是否有上一页*/   
      
private   boolean   hasPrevious;   
      
/**是否有下一页*/   
      
private   boolean   hasNext;   
      
/**总行数   */   
      
private   int   total;   
      
/**总页数   */   
      
private   int   totalPage;   
      
/**当前页码*/   
      
private   int   currentPageNumber=1;   
      
/**跳转动作:1:首页;2:前一页;3:后一页;4:末页*/   
      
private   int   jumpState;   
      
public   void   setPageSize(int   pageSize)   {   
          
this.pageSize   =   pageSize;   
      }
   
      
public   int   getPageSize()   {   
          
return   pageSize;   
      }
   
      
public   void   setHasPrevious(boolean   hasPrevious)   {   
          
this.hasPrevious   =   hasPrevious;   
      }
   
      
public   boolean   getHasPrevious()   {   
          
return   hasPrevious;   
      }
   
        
public   void   setPreviousPageNumber(int   previousPageNumber)   {   
          
this.previousPageNumber   =   previousPageNumber;   
      }
   
        
public   int   getPreviousPageNumber()   {   
          
return   previousPageNumber;   
      }
   
      
public   void   setHasNext(boolean   hasNext)   {   
          
this.hasNext   =   hasNext;   
      }
   
        
public   boolean   getHasNext()   {   
          
return   hasNext;   
      }
   
        
public   void   setNextPageNumber(int   nextPageNumber)   {   
          
this.nextPageNumber   =   nextPageNumber;   
      }
   
      
public   int   getNextPageNumber()   {   
          
return   nextPageNumber;   
      }
   
        
public   void   setTotal(int   total)   {   
          
this.total   =   total;   
      }
   
        
public   int   getTotal()   {   
          
return   total;   
      }
   
        
public   void   setTotalPage(int   totalPage)   {   
          
this.totalPage=totalPage;   
      }
   
        
public   int   getTotalPage()   {   
          
return   totalPage;   
      }
   
        
public   void   setCurrentPageNumber(int   currentPageNumber)   {   
          
this.currentPageNumber=currentPageNumber;   
      }
   
    
        
public   int   getCurrentPageNumber()   {   
          
return   currentPageNumber;   
      }
   
      
public   void   setJumpState(int   jumpState){   
          
this.jumpState=jumpState;   
      }
   
      
public   int   getJumpState(){   
          
return   jumpState;   
      }
   
  }
   
2.分页逻辑方法代码节选:
public     void    setPageInfo(PaginationInfo   paginationInfo)    {   
          
//跳转页   
          if   (paginationInfo.getJumpState()   ==   1)   {   //首页   
              paginationInfo.setCurrentPageNumber(1);   
          }
   
          
if   (paginationInfo.getJumpState()   ==   2)   {   
              paginationInfo.setCurrentPageNumber(paginationInfo.getCurrentPageNumber()   
-   
                                                                                      
1);   
          }
   
          
if   (paginationInfo.getJumpState()   ==   3)   {   
              paginationInfo.setCurrentPageNumber(paginationInfo.getCurrentPageNumber()   
+   
    
                                                                                      
1);   
          }
   
          
if   (paginationInfo.getJumpState()   ==   4)   {   
              paginationInfo.setCurrentPageNumber(paginationInfo.getTotalPage());   
          }
   
          
int   totalPage   =   total   /   paginationInfo.getPageSize();   
          
if   (total   %   paginationInfo.getPageSize()   >   0)   {   
              paginationInfo.setTotalPage(totalPage   
+   1);   
          }
   
          
else   {   
              paginationInfo.setTotalPage(totalPage);   
          }
   
          
if   (paginationInfo.getCurrentPageNumber()   <=   1)   {   
              paginationInfo.setCurrentPageNumber(
1);   
              paginationInfo.setHasPrevious(
false);   
              paginationInfo.setHasNext(
true);   
          }
   
          
else   if   (paginationInfo.getCurrentPageNumber()   >=   
                            paginationInfo.getTotalPage())   
{   
              paginationInfo.setCurrentPageNumber(paginationInfo.getTotalPage());   
              paginationInfo.setHasNext(
false);   
              paginationInfo.setHasPrevious(
true);   
          }
   
          
else   {   
              paginationInfo.setHasPrevious(
true);   
              paginationInfo.setHasNext(
true);   
          }
   
      }
   
 3。jsp页面的分页显示代码节选:
< logic:equal    name ="testForm"    property ="paginationInfo.currentPageNumber"    value ="1" >    
        
< td    align ="right"    width ="30"    height ="22" >< img    src ="images/pages/distop.gif"    alt ="首页"    border ="0" ></ td >    
        
< td    align ="right"    width ="30"    height ="22" >< img    src ="images/pages/disprevious.gif"    alt ="上一页"    border ="0"     ></ td >    
  
</ logic:equal >    
  
< logic:greaterThan    name ="testForm"    property ="paginationInfo.currentPageNumber"    value ="1" >    
        
< td    align ="right"    width ="30"    height ="22" >< a    href ="javascript:gotoPage(1)" >< img    src ="images/pages/top.gif"    alt ="首页"    border ="0"     ></ a ></ td >    
        
< td    align ="right"    width ="30"    height ="22" >< a    href ="javascript:gotoPage(2)" >< img    src ="images/pages/previous.gif"    alt ="上一页"    border ="0" ></ a ></ td >    
  
</ logic:greaterThan >    
  
< logic:equal    name ="testForm"    property ="paginationInfo.hasNext"    value ="false" >    
        
< td    align ="right"    width ="30"    height ="22" >< img    src ="images/pages/disnext.gif"    alt ="下一页"    border ="0"     ></ td >    
          
< td    align ="right"    width ="30"    height ="22" >< img    src ="images/pages/disbottom.gif"    alt ="末页"    border ="0"     ></ td >    
  
</ logic:equal >    
  
< logic:equal    name ="testForm"    property ="paginationInfo.hasNext"    value ="true" >    
                
< td    align ="right"    width ="30"    height ="22" >< a    href ="javascript:gotoPage(3)" >< img    src ="images/pages/next.gif"    alt ="下一页"    border ="0"     ></ a ></ td >    
                
< td    align ="right"    width ="30"    height ="22" >< a    href ="javascript:gotoPage(4)" >< img    src ="images/pages/bottom.gif"    alt ="末页"    border ="0" ></ a ></ td >    
  
</ logic:equal >    
  
< html:hidden    name ="testForm"    property ="paginationInfo.jumpState" >    
  ...//省略   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值