Struts分页源码

/*
QueryAction.java
*/

public class QueryAction extends Action
{
 public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response)
 {
   String str=(String)request.getParameter("PageIndex");
   if(str==null)
   {
    str=1;
   }
  
    int CurrentPageIndex=Integer.parseInt("str");
  

   StudentDAO stuDAO=new StudentDAO();
   PagerController pc=(PagerControler)request.getAttribute("pc");
   if(pc==null)
    {
    pc=new PagerControler();
    ArrayList stus=StuDAO.QueryStudent();
    pc.setBigList(stus);
    request.setAttribute("pc",pc);
    }

    pc.setCurrentPageIndex();
    return new ActionForward("/display.jsp");
 }
};
/*
PagerController.java
*/

public class PagerController
{
 private ArrayList BigList   =null;
 private ArrayList SmallList =null;

 private int CurrentPageIndex= 1;
 private int CountPerPage    = 5;

 private int recordcount;
 private int pagecount;

 private int prePageIndex;
 private int nextPageIndex;

 private boolean firstpage;
 private boolean lastpage;

    public void setCurrentPageIndex(int CurrentPageIndex)
 {
  SmallList=new ArrayList();
  
  prePageIndex=currentPageIndex-1;
  nextPageIndex=currentPageIndex+1;
       
  if(CurrentPageIndex==1)
  {
   firstpage=true;
  }
  else
  {
   firstpage=false;
  }
  if(CurrentPageIndex==pagecount)
  {
   lastpage=true;
  }
  else
  {
   lastpage=false;
  }

  for(int i=(CurrentPageIndex-1)*CountPerPage;i<CurrentPageIndex*CountPerPage&&i<recordcount;i++)
  {
   SmallList.add(BigList.get(i));
  }

 }
 public boolean isFirstpage() {
  return firstpage;
 }
 public void setFirstpage(boolean firstpage) {
  this.firstpage = firstpage;
 }
 public boolean isLastpage() {
  return lastpage;
 }
 public void setLastpage(boolean lastpage) {
  this.lastpage = lastpage;
 }

 public ArrayList getBigList() {
  return BigList;
 }
 public void setBigList(ArrayList BigList) {

  recordcount=BigList.size();
  BigList = bigList;
  if(recordcount%CountPerPage==0)
  {
   pagecount=recordcount/CountPerPage;
  }
  else
  {
   pagecount=recordcount/CountPerPage+1;
  }
 }
 public ArrayList getSmallList() {
  return SmallList;
 }
 public void setSmallList(ArrayList SmallList) {
  SmallList = smallList;
 }
 public int getCurrentPageIndex() {
  return CurrentPageIndex;
 }
 
 public int getCountPerPage() {
  return CountPerPage;
 }

 public void setCountPerPage(int countPerPage) {
  CountPerPage = countPerPage;
 }
  public int getRecordcount() {
  return recordcount;
 }

 public void setRecordcount(int recordcount) {
  this.recordcount = recordcount;
 }

 public int getPagecount() {
  return pagecount;
 }

 public void setPagecount(int pagecount) {
  this.pagecount = pagecount;
 }

 public int getPrePageIndex() {
  return prePageIndex;
 }
 public void setPrePageIndex(int prePageIndex) {
  this.prePageIndex = prePageIndex;
 }
 public int getNextPageInex() {
  return nextPageInex;
 }
 public void setNextPageInex(int nextPageInex) {
  this.nextPageInex = nextPageInex;
 }

};
/*
display.jsp
*/

<html:link action="/query.do?PageIndex=1">首页</html:link>

<logic:equal name="pc" property="firstpage" value="false">
<html:link action="/query.do" paramId="PageIndex" paramName="pc" paramproperty="prePageIndex">上一页</html:link>
</logic:equal>

<logic:equal name="pc" property="lastpage" value="false">
<html:link action="/query.do" paramId="PageIndex" paramName="pc" paramproperty="nextPageIndex">下一页</html:link>
</logic:equal>

<html:link action="/query.do" paramId="PageIndex" paramName="pc" paramproperty="pagecount">尾页</html:link>

 

转载于:https://www.cnblogs.com/JemBai/archive/2009/08/08/1541885.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值