package com.util;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
* JSP自定义分页标签
* @author mushui.tu@kuwo.cn
*
*/
public class PageTag extends TagSupport {
private static final long serialVersionUID = 1L;
private HttpServletRequest request;
/**
* 分页工具的样式,默认为Text
*/
private String style;
/**
* 当前页
*/
private int currentpageInt = 1;
/**
* 每页记录数
*/
private int pagesizeInt = 5;
/**
* 总记录数
*/
private int rscountInt = 0;
/**
* 总页数
*/
private int pagecountInt = 0;
/**
* 分页样式
*/
public final String TEXT = "text";
public final String BBSTEXT = "bbstext";
public final String BBSIMAGE = "bbsimage";
/**
* 分页工具条
*
* @param fileName
* String
* @return String
*/
public String pagetool(String flag) {
StringBuffer str = new StringBuffer();
String url = this.getParamUrl();
int ProPage = this.currentpageInt - 1;
int Nextpage = this.currentpageInt + 1;
if (flag.equals(TEXT)) {
/**
* 论坛形式的分页[直接以数字方式体现]
*/
str.append("<form method='post' name='pageform' action=''>");
str
.append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
str.append("<tr>");
str.append("<td width='3%'> </td>");
str.append("<td height='26'>");
str.append("记录" + this.rscountInt + "条 ");
str.append("共" + this.pagecountInt + "页 ");
str.append("每页" + this.pagesizeInt + "记录 ");
str.append("现在" + this.currentpageInt + "/" + this.pagecountInt
+ "页");
str.append("</td><td>");
// 设定是否有首页的链接
if (this.currentpageInt > 1) {
str.append("<a href='" + url + "¤tpage=1'>首页</a>");
str.append(" ");
}
// 设定是否有上一页的链接
if (this.currentpageInt > 1) {
str.append("<a href='" + url + "¤tpage=" + ProPage
+ "'>上一页</a>");
str.append(" ");
}
// 如果总页数只有10的话
if (this.pagecountInt <= 10) {
for (int i = 1; i <= this.pagecountInt; i++) {
if (this.currentpageInt == i) {
str.append("<font color=red>[" + i
+ "]</font> ");
} else {
str.append("<a href='" + url + "¤tpage=" + i
+ "'>" + i + "</a> ");
}
}
} else {
// 说明总数有超过10页
// 制定特环的开始页和结束页
int endPage = this.currentpageInt + 4;
if (endPage > this.pagecountInt) {
endPage = this.pagecountInt;
}
int startPage = 0;
if (this.pagecountInt >= 8 && this.currentpageInt >= 8) {
startPage = this.currentpageInt - 5;
} else {
// 表示从第一页开始算
startPage = 1;
}
System.out.println(startPage);
System.out.println(endPage);
for (int i = startPage; i <= endPage; i++) {
if (this.currentpageInt == i) {
str.append("<font color=red>[" + i
+ "]</font> ");
} else {
str.append("<a href='" + url + "¤tpage=" + i
+ "'>" + i + "</a> ");
}
}
}
// 设定是否有下一页的链接
if (this.currentpageInt < this.pagecountInt) {
str.append("<a href='" + url + "¤tpage=" + Nextpage
+ "'>下一页</a>");
str.append(" ");
}
// 设定是否有尾页的链接
if (this.pagecountInt > 1
&& this.currentpageInt != this.pagecountInt) {
str.append("<a href='" + url + "¤tpage=" + pagecountInt
+ "'>尾页</a>");
str.append(" ");
}
str.append("转到");
str
.append("<select name='currentPage' onchange='javascript:ChangePage(this.value);'>");
for (int j = 1; j <= pagecountInt; j++) {
str.append("<option value='" + j + "'");
if (currentpageInt == j) {
str.append("selected");
}
str.append(">");
str.append("" + j + "");
str.append("</option>");
}
str.append("<select>页");
str.append("</td><td width='3%'> </td></tr></table>");
str.append("<script language='javascript'>");
str.append("function ChangePage(testpage){");
str.append("document.pageform.action='" + url + "¤tpage='+testpage+'';");
str.append("document.pageform.submit();");
str.append("}");
str.append("</script>");
str.append("</form>");
} else if (flag.equals(BBSTEXT)) {
/**
* 论坛形式的分页[直接以数字方式体现]
*/
str
.append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
str.append("<tr>");
str.append("<td width='3%'> </td>");
str.append("<td height='26'>");
str.append("记录" + this.rscountInt + "条 ");
str.append("共" + this.pagecountInt + "页 ");
str.append("每页" + this.pagesizeInt + "记录 ");
str.append("现在" + this.currentpageInt + "/" + this.pagecountInt
+ "页");
str.append("</td><td>");
// 设定是否有首页的链接
if (this.currentpageInt > 1) {
str.append("<a href='" + url + "¤tpage=1'>首页</a>");
str.append(" ");
}
// 设定是否有上一页的链接
if (this.currentpageInt > 1) {
str.append("<a href='" + url + "¤tpage=" + ProPage
+ "'>上一页</a>");
str.append(" ");
}
// 如果总页数只有10的话
if (this.pagecountInt <= 10) {
for (int i = 1; i <= this.pagecountInt; i++) {
if (this.currentpageInt == i) {
str.append("<font color=red>[" + i
+ "]</font> ");
} else {
str.append("<a href='" + url + "¤tpage=" + i
+ "'>" + i + "</a> ");
}
}
} else {
// 说明总数有超过10页
// 制定特环的开始页和结束页
int endPage = this.currentpageInt + 4;
if (endPage > this.pagecountInt) {
endPage = this.pagecountInt;
}
int startPage = 0;
if (this.pagecountInt >= 8 && this.currentpageInt >= 8) {
startPage = this.currentpageInt - 5;
} else {
// 表示从第一页开始算
startPage = 1;
}
System.out.println(startPage);
System.out.println(endPage);
for (int i = startPage; i <= endPage; i++) {
if (this.currentpageInt == i) {
str.append("<font color=red>[" + i
+ "]</font> ");
} else {
str.append("<a href='" + url + "¤tpage=" + i
+ "'>" + i + "</a> ");
}
}
}
// 设定是否有下一页的链接
if (this.currentpageInt < this.pagecountInt) {
str.append("<a href='" + url + "¤tpage=" + Nextpage
+ "'>下一页</a>");
str.append(" ");
}
// 设定是否有尾页的链接
if (this.pagecountInt > 1
&& this.currentpageInt != this.pagecountInt) {
str.append("<a href='" + url + "¤tpage=" + pagecountInt
+ "'>尾页</a>");
str.append(" ");
}
str.append("</td><td width='3%'> </td></tr></table>");
} else if (flag.equals(this.BBSIMAGE)) {
/**
* 论坛形式的分页[以图片的方式体现]
*/
// 设定分页显示的CSS
str.append("<style>");
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
没有合适的资源?快使用搜索试试~ 我知道了~
JSP自定义分页标签 extends TagSupport
共4个文件
java:2个
tld:1个
jsp:1个
需积分: 16 11 下载量 81 浏览量
2014-02-18
11:59:36
上传
评论
收藏 5KB RAR 举报
温馨提示
JSP自定义分页标签 extends TagSupport 多种分页风格无需额外资源,使用简单易懂:WebRoot/WEB-INF/tms-tags.tld 文件路径
资源推荐
资源详情
资源评论
收起资源包目录
JSP自定义分页标签.rar (4个子文件)
JSP自定义分页标签
tms-tags.tld 1KB
index_page.jsp 2KB
PageTag.java 14KB
PageAction.java 1KB
共 4 条
- 1
资源评论
XT4625
- 粉丝: 136
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 三次样条插值在C语言如何实现步骤介绍.docx
- SD6084电流模式同步降压转换器固定频率1.5MHz二极管封装SOT23-5
- NokoPrint-wifi蓝牙USB连接打印机[安卓免费App]
- 20211115aMmF9NbS.zip
- 解线性方程组-直接解法:(Gauss)高斯消去法、列主元、全主元 - 北太天元
- MapReduce单词统计 hadoop集群
- 深度学习源码神经网络新闻分类多分类问题ipynb源码带数据集
- 深度学习源码神经网络用预训练的卷积神经网络ipynb源码带数据集
- 深度学习源码神经网络使用词嵌入ipynb源码带数据集
- 深度学习源码神经网络使用LSTM生成文本ipynb源码带数据集
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功