Paging logic for Java Web front-end pages

Source: Internet
Author: User

1<div class= "Divbody" >2<div class= "Divcontent" >3<%--Previous Page--%>4<c:choose>//Page is all the object data that you have by querying the current page pagenum is the current page if =1 then (previous page) No connected display out5<c:when test= "${page.pagenum eq 1}" ><span class= "spanbtndisabled" > Prev </span></c:when>6     //Otherwise there is a link to the previous page then the connection value is (current page-1) just fine.7<c:otherwise><a href= "You want to visit the servlet or action&pagenum=${pager.pagenum-1}" class= "Abtn bold" > Prev </ A></c:otherwise>8</c:choose>9         Ten          One  A<%--we need to calculate the start and end of the page number list, that is, two variables, begin and end - calculate what they need to pass through the current page!  - below try a page to show only 6 pages on the basis of course you want to show how much you can set your own the1. Total pages less than 6 pages-begin=1, end=Maximum page -2. Set begin and end,begin= by Formula pagenum-2,end= Current page pagrnum+3 -3. If begin<1, then let begin=1,end=6 -4. If end> max page, let begin= total number of pages-5, end=Total Pages +--%> -  +  //Total Pages: Page.pagecount A  //Current page: Page.pagenum at<c:choose> -     //because we only show 6 pages of data on the page if the total number of pages is less than 6. -<c:when test= "${total pages <= 6}" > -<c:setvar= "Begin" value= "1"/>//set the value of Begin is 1 -<c:setvar= "End" value= "total pages"/>//Set end value is the total number of pages -</c:when> in     //otherwise do the following things -<c:otherwise> to         //if the total number of pages is greater than 6, here we assume that the total number of pages is 7 pages then the page is displayed as 1 2 3 4 5 6 ... +         //Let's take a look at a couple of things. -         //1. Current page if the 3rd page bengin is 3-2=1 end is 3+3=6 then the page display is 1 2 3 4 5 6 ... the         //2. Current page If the 4th page of the word begin is 4-2=2 end is 4+3=7 then the page display is 2 3 4 5 6 7 no ellipsis 1 and ... Disappear *         //3. Current page if it is page 5,6,7 begin is 5-2=3 6-2=4 7-2=5 end is 5+3=8 6+3=9 7+3=10 but the maximum page is 7 not to 8 9 10 will be the following Judgment page Display 2 3 4 5 6 7 $         //4. Current page If it is 1th, 2 pages of the word begin is 1-2=-1 and 2-2=0 end is 1+3=4 2+3=5 but start page begin must be 1 can not meet the situation will be the following judgment page display 1 2 3 4 5 6 ...Panax Notoginseng<c:setvar= "Begin" value= "${current page -2}"/> -<c:setvar= "End" value= "${current page + 3}"/> the         //if the begin is 1 and 0 then less than 1 then set the start page begin to 1 end page end for 6 page display 1 2 3 4 5 6 ... +<c:ifTest= "${begin < 1}" > A<c:setvar= "Begin" value= "1"/> the<c:setvar= "End" value= "6"/> +</c:if> -         //If the end page is greater than the total number of pages, which is the third case above, the end page is 8 9 10, then the total number of pages is more than 7 then set start bengin The current page is the total number of pages 7-5=2 $         //the end is the total number of pages displayed as 2 3 4 5 6 7 $<c:ifTest= "${end > Total pages}" > -<c:setvar= "Begin" value= "${Total pages-5}"/> -<c:setvar= "End" value= "${Total pages}"/> the</c:if> -</c:otherwise>Wuyi</c:choose> the   -  //gets the value loop to begin and end Wu<c:foreach begin= "${begin}" end= "${end}"var= "I" > -<c:choose> About<c:when test= "${i eq Current page}" > $<span class= "Spanbtnselect" >${i}</span>//if I equals current page then do not give link -</c:when> -<c:otherwise> -<a href= "${you access the action or servlet}&pc=${i}" class= "abtn" >${i}</a>//otherwise it will give the link A</c:otherwise> +</c:choose> the             -                $</c:forEach> the<%--compute begin and End--%> the<%--if the total number of pages <=6, then show all page numbers, that is, Begin=1 end=${total pages}--%> the<%--set begin= Current page number -2,end= current page +3--%> the<%--if begin<1, then let Begin=1 end=6--%> -<%--if end> max page, then begin= max page -5 end= max page--%> in  the  the     //If the end page is less than the total number of pages 7 then show ... About<%--Display Point Point--%> the<c:ifTest= "${end < Total pages}" > the<span class= "Spanapostrophe" >...</span> the</c:if> +  -      the<%--Next--%>Bayi<c:choose> the<c:when test= "${current page eq total pages}" ><span class= "spanbtndisabled" > Next </span></c:when> the<c:otherwise><a href= "${the action and servlet you want to access}&pagenum=${current page +1}" class= "Abtn bold" > Next </a> </c:otherwise> -</c:choose> -          the          the&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the      the<%--total n pages to M page--%> -<span> Total ${page.pagecount} page </span> the<span> to </span> the<input type= "text" class= "Inputpagecode" id= "Pagecode" value= "${current page}"/> the<span> page </span>94<a href= "Javascript:_go (); class=" Asubmit "> OK </a> the</div> the</div>

Paging logic for Java Web front-end pages

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.