pager-taglib使用示范

  1. 把pager-taglib.jar导入到当前项目/Test/WebRoot/WEB-INF/lib下
  2. 建立一个分页类
    package web;
    
    import java.util.List;
    
    /**
     * 分页模型
     * 
     */
    public class PagerModel {
    
    	// 总记录数
    	private int total;
    	// 当前页的结果集
    	private List datas;
    
    	public int getTotal() {
    		return total;
    	}
    
    	public void setTotal(int total) {
    		this.total = total;
    	}
    
    	public List getDatas() {
    		return datas;
    	}
    
    	public void setDatas(List datas) {
    		this.datas = datas;
    	}
    
    }
    

     

  3. 建立一个JSP页面
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
    <%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
    <html>
    <head>
    <base href="<%=basePath%>">
    <title>新闻列表</title>
    </head>
    <body>
    <pg:pager items="22" url="news.do" index="half-full" maxPageItems="5"
    		maxIndexPages="10" isOffset="<%=false%>"
    		export="pageOffset,currentPageNumber=pageNumber" scope="request">
      <pg:param name="method" value="all" />
      <table align="center">
        <c:forEach items="${newsList}" var="nlist">
          <tr>
            <td>${nlist.sort.stname}</td>
            <td><a href="news.do?method=info&nid=${nlist.nid}"
    						target="_blank">${nlist.ntitle}</a></td>
            <td><fmt:formatDate value="${nlist.ntime}"
    							pattern="yyyy/MM/dd HH:mm" /></td>
          </tr>
        </c:forEach>
      </table>
      <pg:index export="total=itemCount">
        <center>
          <table border=1 cellpadding=0 width=70% cellspacing=0>
            <tr align=center valign=top>
              <pg:first>
                <td width="50">总计${total}个记录,第${currentPageNumber} /
                  <fmt:formatNumber pattern="0" value="${total % 5 == 0 ? total / 5 :total / 5 +1}" />
                  页</td>
                <c:choose>
                  <c:when test="${currentPageNumber ne pageNumber}">
                    <td width="50"><a href="<%=pageUrl%>&pageNo=<%=pageNumber%>"><b>首页</b> </a></td>
                  </c:when>
                  <c:otherwise>
                    <td width="50"><b>首页</b></td>
                  </c:otherwise>
                </c:choose>
              </pg:first>
              <pg:prev ifnull="true">
                <c:choose>
                  <c:when test="${!empty pageUrl}">
                    <td width="50"><a href="<%=pageUrl%>&pageNo=<%=pageNumber%>"><b>上一页</b> </a></td>
                  </c:when>
                  <c:otherwise>
                    <td width="50"><b>上一页</b></td>
                  </c:otherwise>
                </c:choose>
              </pg:prev>
              <pg:pages>
                <c:choose>
                  <c:when test="${currentPageNumber eq pageNumber}">
                    <td width="10"><font color="red">${pageNumber}</font></td>
                  </c:when>
                  <c:otherwise>
                    <td width="10"><a href="${pageUrl}&pageNo=${pageNumber}">${pageNumber}</a></td>
                  </c:otherwise>
                </c:choose>
              </pg:pages>
              <pg:next ifnull="true">
                <c:choose>
                  <c:when test="${!empty pageUrl}">
                    <td width="50"><a href="${pageUrl}&pageNo=${pageNumber}">下一页</a></td>
                  </c:when>
                  <c:otherwise>
                    <td width="50"><b>下一页</b></td>
                  </c:otherwise>
                </c:choose>
              </pg:next>
              <pg:last>
                <c:choose>
                  <c:when test="${currentPageNumber ne pageNumber}">
                    <td width="50"><b><a href="${pageUrl}&pageNo=${pageNumber}">尾页</a></b></td>
                  </c:when>
                  <c:otherwise>
                    <td width="50"><b>尾页</b></td>
                  </c:otherwise>
                </c:choose>
              </pg:last>
            </tr>
          </table>
        </center>
      </pg:index>
    </pg:pager>
    </body>
    </html>
    

     

posted @ 2015-04-07 20:21  koal  阅读(247)  评论(0编辑  收藏  举报