分页类
package com.a.a;public class PageBean {private int nowpage;//当前页码 private int yemashuliang;//页码数量private int pagesize;//每页显示数量private int shouye;//首页private int weiye;//尾页页码private int shangyiye;//上一页页码private int xiayiye;//下一页页码private int kaishiye;// 显示页码的开始页private int jieshuye;//显示页码的结束页private int count;//查询出的数据量public PageBean(int count,int pagesize,int nowpage) {this.count=count;this.nowpage = nowpage;//当前页this.pagesize=pagesize;yemashuliang = 1;//页码数yemashuliang = count / pagesize + 1;if (count % pagesize == 0) {yemashuliang = count / pagesize;}shouye = 1;// 首页weiye = yemashuliang;// 尾页shangyiye = nowpage - 1;// 上一页if (shangyiye >= 1) {shangyiye = 1;}xiayiye = nowpage + 1;// 下一页if (xiayiye >= yemashuliang) {xiayiye = yemashuliang;}if (nowpage>=weiye) {this.nowpage=weiye;}kaishiye=1;kaishiye=nowpage-4;jieshuye=nowpage+5;if (nowpage%2==1 ) {jieshuye=nowpage+5;}if (jieshuye>=yemashuliang) {jieshuye=yemashuliang;kaishiye=jieshuye-9;}if (jieshuye<10&&yemashuliang>=10) {jieshuye=10;}if (kaishiye<=0) {kaishiye=1;}if (kaishiye==1 && yemashuliang<10 && jieshuye!=yemashuliang ) {jieshuye=yemashuliang;}}public PageBean(){}public int getNowpage() {return nowpage;}public void setNowpage(int nowpage) {this.nowpage = nowpage;}public int getYemashuliang() {return yemashuliang;}public void setYemashuliang(int yemashuliang) {this.yemashuliang = yemashuliang;}public int getMeiyexianshi() {return pagesize;}public void setMeiyexianshi(int pagesize) {this.pagesize = pagesize;}public int getShouye() {return shouye;}public void setShouye(int shouye) {this.shouye = shouye;}public int getWeiye() {return weiye;}public void setWeiye(int weiye) {this.weiye = weiye;}public int getShangyiye() {return shangyiye;}public void setShangyiye(int shangyiye) {this.shangyiye = shangyiye;}public int getXiayiye() {return xiayiye;}public void setXiayiye(int xiayiye) {this.xiayiye = xiayiye;}public int getCount() {return count;}public void setCount(int count) {this.count = count;}public int getPagesize() {return pagesize;}public void setPagesize(int pagesize) {this.pagesize = pagesize;}public int getKaishiye() {return kaishiye;}public void setKaishiye(int kaishiye) {this.kaishiye = kaishiye;}public int getJieshuye() {return jieshuye;}public void setJieshuye(int jieshuye) {this.jieshuye = jieshuye;}}//在Action中的使用public String executeImg() {if (nowpage==null) {nowpage=1;}/*分页信息*/ int count=0;/*分页信息 判断每页数量cookie*///数据总数count=newsInfoDAO.getNewsinfoCountNewstype(t);if (count!=0) {p=new PageBean(count,pagesize,nowpage);//获取分类下的文档列表newsInfos=newsInfoDAO.getNewsinfoPageNewstype(t,p.getPagesize() ,p.getNowpage());}if (t!=null) {newsTypecn=newsTypecnDAO.findByNewstypeid(language, t);}return SUCCESS;}//JSP+struts2在页面中的使用<!-- page --><s:if test="p!=null"><div href="/<s:property value="#locale" />/news/llist/<s:property value="t" />/<s:property value="p.nowpage-1" />.html" ><s:text name="news_list_shangyiye" /></a></s:if><s:iterator id="page" begin="p.kaishiye" end="p.jieshuye" ><s:if test="#page==p.nowpage"> <span /></span></s:if><s:else > <a href="/<s:property value="#locale" />/news/llist/<s:property value="t" />/<s:property value="#page" />.html" ><s:property value="#page" /></a> </s:else></s:iterator><s:if test="p.nowpage!=p.weiye"><a id="next-page" href="/<s:property value="#locale" />/news/llist/<s:property value="t" />/<s:property value="p.nowpage+1" />.html" /><s:text name="news_list_xiayiye" /></a></s:if></div></s:if><!-- page -->