JSP Paging Code

Source: Internet
Author: User

<%@ page language= "java"  import= "java.util.*"  pageencoding= "UTF-8"%><%@  Taglib uri= "Http://java.sun.com/jsp/jstl/core"  prefix= "C"%><!--  Pager start  -->                         ${page.pagenum} page/Total ${page.totalpage} page               <a href= "${pagecontext.request.contextpath}${page.servleturl}" > Home </a>              <a href= "${ pagecontext.request.contextpath}${page.servleturl}?pagenum=${(page.pagenum-1) >0? ( page.pagenum-1): 1} "> Prev </a>                         <c:foreach begin= "${ Page.startpage} " end=" ${page.endpage} " var=" num ">                    <a href= "${pagecontext.request.contextpath}${page.servleturl}?pagenum=${num}" >[${num}]</a>                      </c:forEach>           <a  Href= "${pagecontext.request.contextpath}${page.servleturl}?pagenum=${(page.pagenum+1) >page.totalPage? Page.totalpage: (page.pagenum+1)} "> Next </a>              <a href= "${pagecontext.request.contextpath}${page.servleturl}?pagenum=${ Page.totalpage} "> Last </a>
           <select id= "S1"  name= "S1" >                     <c:foreach begin= "1"  end= "${page.totalpage}"  var= "num" >                             <option value= "${num}"                                                                            ${page.pagenum==num? ' Selected= "Selected" ': '}&GT;${NUM}&LT;/OPTION&GT;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&LT;/C: foreach>           </select>              <input type= "button"  value= "Jump"   onclick= "Jump ()"/>           <script type= " Text/javascript ">                    function jump () {                         var num =  document.getElementById ("S1") .value;                         window.location.href= "${ Pagecontext.request.contextpath}${paGe.servleturl}?pagenum= "+num;                    }           </ script>           <!--  End of page navigation  -->                        javabean Layer:        private list  records;//the records of the page display                 DAO can find out         private int pagenum;//current page number                                     page upload hand over, default 1th page          private int totalpage;//Total Pages                                     Calculated: Total number of records and Pagesize        private int pagesize  = 10;//number of records displayed per page         private int totalrecords ;//Total number of records                   DAO can find out the index number of the start record of         private int startindex;//per page              can figure out:         private int startpage;//page display: Start Page         private  int endpage;//page number display: End page number         public page (Int pageNum, Int totalrecords){                this.pagenum  = pageNum;                 this.totalRecords = totalRecords;                 //Calculate Total Pages                  totalPage =  (totalrecords%pagesize==0)? (totalrecords/pagesize):(totalrecords/pagesize+1);                 //calculate the index of the start record for each page                  startIndex =  (pageNum-1) *pagesize;                 //Calculate start and end page numbers              &nbSp;   if (totalpage<=9) {                         startPage = 1;                          endPage = totalPage;                 }else{                         startpage =  pageNum-4;                         endPage = pageNum+4;                          if (startpage<1) {&Nbsp;                                startPage = 1;                                  endPage = 9;                          }                         if (endpage>totalpage) {                                  endPage = totalPage;                                  startPage = endPage-8;                          }                }         }


This article is from the "heavy Shoulder" blog, please be sure to keep this source http://534256702.blog.51cto.com/10669156/1691632

JSP Paging Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.