jsp查询结果分页
<% int allpage=1; //总的页码数 int currpage=0;//当前页码数 int startpage=1;//起始页码数 int rec=9;//记录总数 int dispn=7;//总共显示的页码数 int halfdisp=3;//显示页数的一半 int endpage=0;//显示的最大页码 allpage=(int)Math.ceil(rec/2.0);//计算总的页码数 String s=request.getParameter("page");//初始化当前页 if ( s==null){//第一次浏览就设置当前页码为1 currpage=1; } else { currpage=Integer.parseInt(s); } if (allpage<=dispn){ //总数少于指定显示页数,就直接显示 startpage=1; endpage=allpage; } else { if(allpage-currpage<3){ startpage=allpage-halfdisp*2; endpage=allpage; } else { if ((currpage-halfdisp)<=0){ startpage=1; } else { startpage=currpage-halfdisp; if ((allpage-startpage)<(halfdisp*2)){ startpage=allpage-halfdisp*2; } } if ((startpage+dispn)<=allpage) { endpage=startpage+dispn-1; } else { endpage=allpage; } } } for(int i=startpage;i<=endpage;i++){//显示后半部分页码 out.print(" <a href='index.jsp?page="+ i +"'>"+ i +"</a> "); } %>