zoukankan      html  css  js  c++  java
  • JSP 结果分页实现

     1 html中的核心代码:
      jsp查询结果分页
    写在<body>标签中
    5 <%
    6 int allpage=1; //总的页码数
    7 int currpage=0;//当前页码数
    8 int startpage=1;//起始页码数
    9 int rec=9;//记录总数
    10 int dispn=7;//总共显示的页码数
    11 int halfdisp=3;//显示页数的一半
    12 int endpage=0;//显示的最大页码
    13
    14 allpage=(int)Math.ceil(rec/2.0);//计算总的页码数
    15
    16 String s=request.getParameter("page");//初始化当前页
    17 if ( s==null){//第一次浏览就设置当前页码为1
    18 currpage=1;
    19 } else {
    20 currpage=Integer.parseInt(s);
    21 }
    22
    23 if (allpage<=dispn){ //总数少于指定显示页数,就直接显示
    24 startpage=1;
    25 endpage=allpage;
    26 } else {
    27 if(allpage-currpage<3){
    28 startpage=allpage-halfdisp*2;
    29 endpage=allpage;
    30 } else {
    31 if ((currpage-halfdisp)<=0){
    32 startpage=1;
    33 } else {
    34 startpage=currpage-halfdisp;
    35 if ((allpage-startpage)<(halfdisp*2)){
    36 startpage=allpage-halfdisp*2;
    37 }
    38 }
    39 if ((startpage+dispn)<=allpage) {
    40 endpage=startpage+dispn-1;
    41 } else {
    42 endpage=allpage;
    43 }
    44 }
    45 }
    46
    47 for(int i=startpage;i<=endpage;i++){//显示后半部分页码
    48 out.print("&nbsp;<a href='index.jsp?page="+ i +"'>"+ i +"</a>&nbsp;");
    49 }
    50
    51 %>

    参考:

    JSP数据分页实例:MySQL翻页:http://www.soft6.com/html/tech/16/160176.shtml

  • 相关阅读:
    实验3
    实验2
    实验1
    阿里云服务器搭建Halo博客系统
    移动开发技术(三)
    在服务器上部署Anki-Server
    软件测试技术(二)
    函数相关定理
    移动开发技术(一)
    高等数学函数求导
  • 原文地址:https://www.cnblogs.com/javadu/p/2262322.html
Copyright © 2011-2022 走看看