Java Web page numbering pagination

Source: Internet
Author: User

The beginning of the show is 1,2,3,4,5 the second page is when I click 2,3 when the display or 1,2.3,4,5 Click 4 when the display is 2,3,4,5,65 when the 3,4,5,6,76 is 4,5,6,7,8
package com.kt.servlet_qt;import java.io.ioexception;import java.io.printwriter;import  java.util.arraylist;import java.util.list;import javax.servlet.servletexception;import  javax.servlet.http.cookie;import javax.servlet.http.httpservlet;import  javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import  Com.kt.bean.easybuy_shangpin;import com.kt.dao.impl.easybuyimpl;public class ecommodityservlet  extends httpservlet {public void doget (httpservletrequest request,  Httpservletresponse response) Throws servletexception, ioexception {printwriter out  = response.getwriter (); Easybuyimpl e = new easybuyimpl ();//  shows how many data int pagesize = 8;//  Get total number of items int record = e.total ();//  calculates how many pages a product has int totalpage = record %  pagesize == 0 ?  (record / pagesize)  :  (record/ pagesize + 1);//  get how many pages string  Curpage = request.getparameter ("Curpage");//  current page int count = -1;if  (curpage  != null)  {count = integer.parseint (curpage);//  determine if the current page is less than 0if  ( Integer.parseint (curpage)  < 1)  {count = 1;}   Determine whether the current page exceeds the existing page if  (Integer.parseint (curpage)  >= totalpage)  {count =  Totalpage;}}  else {count = 1;}   Paging List<easybuy_shangpin> findall_shangpinfenye = e.findall_shangpinfenye ((count  - 1)  * pagesize, pagesize);//  Total pages request.getsession (). SetAttribute ("TotalPage",  totalpage);//  current page request.getsession (). SetAttribute ("Count",  count);//  Number of pages of data request.getsession (). SetAttribute ("Findall_shangpinfenye", findall_shangpinfenye); Request.getrequestdispatcher ("product-list.jsp"). Forward (reqUest,response); Out.flush (); Out.close ();}} 
<div class= "Pager" ><ul class= "Clearfix" ><li><a href= "Ecommodityservlet? Curpage=${count-1} "> Prev </a></li><c:choose><c:when test=" ${COUNT&LT;=3&NBSP;} "> <c:foreach begin= "0"  end= "4"  var= "V" ><c:if test= "${count==v+1}" ><li>< a href= "Ecommodityservlet?curpage=${count-1}" style= "color: red" >${v+1 }</a></li> </c:if><c:if test= "${count!=v+1}" ><li><a href= "ecommodityservlet?curpage=${v+1} ">${v+1}</a></li></c:if></c:foreach></c:when><c:when test=" ${count  < totalpage-3 } "><c:foreach begin=" ${COUNT-2&NBSP;} " end=" ${COUNT+2&NBSP;} "  var= "V" ><c:if test= "${count==v+1 }" ><li><a href= "Ecommodityservlet? curpage=${v+1} "style=" color: red ">${v+1 }</a></li></c:if><c:if test=" ${ COUNT!=V+1} "><li><a href= "Ecommodityservlet?curpage=${v+1}" &GT;${V+1}&LT;/A&GT;&LT;/LI&GT;&LT;/C:IF&GT;&LT;/C: Foreach></c:when><c:otherwise><c:foreach begin= "${TOTALPAGE-5&NBSP;}"  end= "${ totalpage-1 } " var=" V "><c:if test=" ${count==v+1 } "><li><a href=" ecommodityservlet?curpage=${v+1} "style=" color: red ">${v+1 }</a></li></c:if>< C:if test= "${COUNT!=V+1&NBSP;}" ><li><a href= "Ecommodityservlet?curpage=${v+1}" >${v+1} </a></li></c:if></c:forEach></c:otherwise></c:choose><li><a  href= "Ecommodityservlet?curpage=${ count+1}" > next page </a></li></ul></div></div ></div>

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/7F/7F/wKioL1cgw9-B88tDAAGsAkkjxJw151.jpg "style=" float: none; "Title=" h9gw7%t4@ (4p[4hya9 (] @R7. jpg "alt=" wkiol1cgw9-b88tdaagsakkjxjw151.jpg "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/81/wKiom1cgwxei3EbdAAAVzl1uRAQ312.png "style=" float: none; "title=" YU ' zezgy}d[) fjdnm8i4klm.png "alt=" Wkiom1cgwxei3ebdaaavzl1uraq312.png "/>


Java Web page numbering pagination

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.