分页标签

1 编写标签类

package org.springside.modules.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.springside.modules.orm.Page;

public class PageTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;

private Page page;

public void setPage(Page page) {
this.page = page;
}

@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
StringBuffer sb = new StringBuffer("");
sb.append(
"<input type='hidden' name='page.pageNo' id='pageNo' value='"
+ page.getPageNo() + "' />").append(
"<input type='hidden' name='page.orderBy' id='orderBy' value='"
+ page.getOrderBy() + "' />").append(
"<input type='hidden' name='page.order' id='order' value='"
+ page.getOrder() + "' />").append(
"<span> 第" + page.getPageNo() + "/" + page.getTotalPages()
+ "页 </span>");
if (!page.isHasPre())
sb.append("<span>首页</span><span class=\"pre\">上一页</span>");
if (page.isHasPre())
sb.append("<a href=\"javascript:void()\" id=\"1\">首页</a>").append(
"<a href=\"javascript:void()\" class=\"pre\" id=\""
+ page.getPrePage() + "\">上一页</a>");
if (page.isHasNext())
sb.append(
"<a href=\"javascript:void()\" class=\"next\" id=\""
+ page.getNextPage() + "\">下一页</a>").append(
"<a href=\"javascript:void()\" id=\""
+ page.getTotalPages() + "\">末页</a>");
if (!page.isHasNext())
sb.append("<span class=\"next\">下一页</span><span>末页</span>");
sb.append(" 当前共有" + page.getTotalCount() + "条记录");

try {
if (sb != null)
out.println(sb);
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}

@Override
public int doStartTag() throws JspException {
return EVAL_PAGE;
}

}


2 TLD文件 必须放在WEB-INF/tlds文件夹下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>page</short-name>
<uri>/pagetag</uri>
<!--OutputTag-->
<tag>
<name>out</name>
<tag-class>org.springside.modules.tag.PageTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>page</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>


3 页面引用

<%@ taglib prefix="p" uri="/pagetag" %>



<p:out page="${page}"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值