/*
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>