分享一些在jsp上面自定义的一些标签,希望对大家有所帮助;
public class PagerData {
//当前页的数据
private List data;
//总记录数
private int total;
//当前页
private int currentPage;
//每页大小
private int pagesize;
//总页数
public int getTotalPage(){
int tpage = total / pagesize;
if(total % pagesize != 0)
tpage ++;
return tpage;
}
//开始行
public int getStartRow(){
int start = (currentPage - 1) * pagesize;
start ++;
return start;
}
//结束行
public int getEndRow(){
int end = currentPage * pagesize;
if(end > total){
end = total;
}
return end;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
}
page.tag代码:<%@ tag language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ attribute name="url" required="true" type="java.lang.String"%>
<%@ attribute name="pagedata" required="true" type="com.fbtt.site.utils.PagerData" %>
<div>
<c:set var="tourl" value='<%=url + ((url.indexOf("?")>=0)?"&":"?")%>'></c:set>
<a href="${tourl}topage=1">第一页</a>
<c:if test="${pagedata.currentPage > 1}">
<a href="${tourl}topage=${pagedata.currentPage-1}">上一页</a>
</c:if>
<c:if test="${pagedata.currentPage < pagedata.totalPage}">
<a href="${tourl}topage=${pagedata.currentPage+1}">下一页</a>
</c:if>
<a href="${tourl}topage=${pagedata.totalPage}">第末页</a>
记录:${pagedata.startRow}-${pagedata.endRow}/${pagedata.total},
页码:${pagedata.currentPage}/${pagedata.totalPage}
</div>
jsp自定义标签非常简单,你只需要有jstl库的支持即可,首先在工程里面新建tag文件,就可以直接自定义自己的标签