java分页工具源码.doc_第1页
java分页工具源码.doc_第2页
java分页工具源码.doc_第3页
java分页工具源码.doc_第4页
java分页工具源码.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

package mon.util.web;import java.io.IOException;import java.util.Enumeration;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.PageContext;import javax.servlet.jsp.tagext.TagSupport;public class PageUtilTag extends TagSupport private int rscount = 0; / 一共有多少行private int pagesize = 20; / 每页有多少行默认为20行private int type = 1;/ 默认值为1private String url = ;/* * 下面这些参数不需要页面传递 */private int pageCount = 0;private int currentPage = 1;private HttpServletRequest request;public String getUrl() return url;public void setUrl(String url) this.url = url;public int getType() return type;public void setType(int type) this.type = type;public int getRscount() return rscount;public void setRscount(int rscount) this.rscount = rscount;public int getPagesize() return pagesize;public void setPagesize(int pagesize) this.pagesize = pagesize;Overridepublic int doEndTag() throws JspException PageContext pageContext = this.pageContext;HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();this.request = request;HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();JspWriter out = pageContext.getOut();/ 获取总记录数int rsCount = this.getRscount();/ 获取每页显示多少条int pageSize = this.getPagesize();/ 获取总记录数int pageCount = this.getpageCount();/ 获取当前页int currentPage = this.getcurrentPage(request);/ 创建工具条String pageTool = this.createPageTool(this.type);try out.println(pageTool); catch (IOException e) e.printStackTrace();return super.doEndTag();/* * 获取总页数 * * return int */private int getpageCount() try this.pageCount = (this.rscount - 1) / this.pagesize) + 1; catch (Exception ex) ex.printStackTrace();this.pageCount = 0;return this.pageCount;/* * 获取当前页码的设置 * * return int */private int getcurrentPage(HttpServletRequest request) try if (request.getParameter(currentPage) != null& Integer.parseInt(request.getParameter(currentPage) 1) this.currentPage = Integer.parseInt(request.getParameter(currentPage); else this.currentPage = 1; catch (Exception ex) ex.printStackTrace();this.currentPage = 1;return this.currentPage;/* * 分页工具条 * * param fileName * String * return String */private String createPageTool(int type) StringBuffer str = new StringBuffer();String temp = ;String url = this.getParamUrl();int ProPage = this.currentPage - 1;int Nextpage = this.currentPage + 1;/ 文字的分页if (type = 1) str.append();str.append();str.append();str.append( );str.append();str.append(共有记录 + this.rscount + 条   );str.append(共 + this.pageCount + 页   );str.append(每页 + this.pagesize + 记录   );str.append(现在 + this.currentPage + / + this.pageCount + 页);str.append();if (this.currentPage 1) str.append(首页);str.append(   );str.append(上一页);str.append(   ); else str.append(首页);str.append(   );str.append(上一页);str.append(   );if (this.currentPage this.pageCount) str.append(下一页);str.append(   ); else str.append(下一页);str.append(   );if (this.pageCount 1 & this.currentPage != this.pageCount) str.append(尾页);str.append(   ); else str.append(尾页);str.append(   );str.append(转到);str.append();for (int j = 1; j = pageCount; j+) str.append();str.append( + j + );str.append();str.append(页);str.append( );str.append();str.append(function ChangePage(testpage);str.append(document.pageform.action= + url+ ¤tPage=+testpage+;);str.append(document.pageform.submit(););str.append();str.append();str.append(); else if (type = 2) /* * 论坛形式的分页直接以数字方式体现 */str.append();str.append();str.append( );str.append();str.append(记录 + this.rscount + 条  );str.append(共 + this.pageCount + 页  );str.append(每页 + this.pagesize + 记录  );str.append(现在 + this.currentPage + / + this.pageCount + 页);str.append();/ 设定是否有首页的链接if (this.currentPage 1) str.append(首页);str.append(  );/ 设定是否有上一页的链接if (this.currentPage 1) str.append(上一页);str.append(   );/ 如果总页数只有10的话if (this.pageCount = 10) for (int i = 1; i = this.pageCount; i+) if (this.currentPage = i) str.append( + i+   ); else str.append( + i +   ); else / 说明总数有超过10页/ 制定特环的开始页和结束页int endPage = this.currentPage + 4;if (endPage this.pageCount) endPage = this.pageCount;int startPage = 0;if (this.pageCount = 8 & this.currentPage = 8) startPage = this.currentPage - 5; else / 表示从第一页开始算startPage = 1;System.out.println(startPage);System.out.println(endPage);for (int i = startPage; i = endPage; i+) if (this.currentPage = i) str.append( + i+   ); else str.append( + i +   );/ 设定是否有下一页的链接if (this.currentPage this.pageCount) str.append(下一页);str.append(  );/ 设定是否有尾页的链接if (this.pageCount 1 & this.currentPage != this.pageCount) str.append(尾页);str.append(  );str.append( ); else if (type = 3) /* * 论坛形式的分页以图片的方式体现 */ 设定分页显示的CSSstr.append();str.append(BODY FONT-SIZE: 12px;FONT-FAMILY:宋体;WIDTH: 60%; PADDING-LEFT: 25px;);str.append(DIV.meneame PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 80%; PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #ff6500; PADDING-TOP: 3px; TEXT-ALIGN: center);str.append(DIV.meneame A BORDER-RIGHT: #ff9600 1px solid; PADDING-RIGHT: 7px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ff9600 1px solid; PADDING-LEFT: 7px; BACKGROUND-IMAGE: url(+ this.request.getContextPath()+ /meneame.jpg); PADDING-BOTTOM: 5px; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff9600 1px solid; TEXT-DECORATION: none);str.append(DIV.meneame A:hover BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; BACKGROUND-COLOR: #ffc794);str.append(DIV.meneame SPAN.current BORDER-RIGHT: #ff6500 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ff6500 1px solid; PADDING-LEFT: 7px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; BORDER-LEFT: #ff6500 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff6500 1px solid; BACKGROUND-COLOR: #ffbe94);str.append(DIV.meneame SPAN.disabled BORDER-RIGHT: #ffe3c6 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ffe3c6 1px solid; PADDING-LEFT: 7px; PADDING-BOTTOM: 5px; BORDER-LEFT: #ffe3c6 1px solid; COLOR: #ffe3c6; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ffe3c6 1px solid);str.append();str.append();/ 判定是否有上一页if (this.currentPage 1) str.append(首页);str.append(   );str.append(上一页);str.append(   ); else str.append(首页);str.append(  );str.append(上一页);str.append(  );/ 显示中间的图片if (this.pageCount = 10) for (int i = 1; i = this.pageCount; i+) if (this.currentPage = i) str.append( + i + ); else str.append( + i+   ); else / 说明总数有超过10页/ 制定特环的开始页和结束页int endPage = this.currentPage + 4;if (endPage this.pageCount) endPage = this.pageCount;int startPage = 0;if (this.pageCount = 8 & this.currentPage = 8) startPage = this.currentPage - 5; else / 表示从第一页开始算startPage = 1;System.out.println(startPage);System.out.println(endPage);for (int i = startPage; i = endPage; i+) if (this.currentPage = i) str.append( + i + ); else str.append( + i+   );/ 判断下一页和尾页if (this.currentPage this.pageCount) if (this.currentPage this.pageCount - 10) str.append(.);str.append(+ (this.pageCount - 1) +   );str.append(+ this.pageCount +   );str.append(下一页);str.append(  ); else str.append(下一页);str.append(  );if (this.pageCount 1 & this.currentPage != this.pageCount) str.append(尾页);str.append(  ); else str.append(尾页);str.append(  );str.append();return str.toString();public String getParamUrl() String url = ;url = this.request.getContextPath() + / + this.getUrl();if (url.indexOf(?) = -1) url = url + ?;String totalParams = ;Enumeration params = this.request.getParameterNames();/ 得到所有参数名while (params.hasMoreElements() String tempName = params.nextElement().toString();String tempValue = this.request.getParameter(tempName);if (tempValue != null & !tempValue.equals()& !tempName.equals(currentPage) if (totalParams.equals() totalParams = totalParams + tempName + = + tempValue; else totalParams = totalParams + & + tempName + =+ tempValue;String totalUrl = url + totalParams;return totalUrl;public static void main(String args) / 调用方式/ Servlet中/ 定义每页显示多少条/ int pageSize = 13;/ 获取总记录数/ String sql = Select count(itemid) from t_iteminfo;/ int rsCount = ConnOracle.getCount(sql);/ request.setAttribute(rsCount, rsCount);/ int current

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论