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>

pager-taglib使用示范的更多相关文章

  1. pager-taglib分页处理的使用

    pager-taglib是java中一个用于分页的小的框架.下面简单介绍一下它的具体使用. 一.环境的搭建: 将pager-taglib-2.0.war包拷贝到Tomcat的webapps下.启动To ...

  2. springmvc 孔浩 hibernate code

    model--User package model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; ...

  3. 分页技术框架(Pager-taglib)学习二(SSH数据库分页)

    一.Pager-taglib数据库分页前提    Pager-taglib分页标签也可以实现数据库分页,与页面分页不同的是需要给后台传两个参数,一个是pageNo(当前页数)或pageOffset(偏 ...

  4. struts2:上传多个文件时实现带进度条、进度详细信息的示范

    上一篇文章讲了上传单个文件与上传多个文件(属性驱动)的例子.本例是上传多个文件(属性驱动),并且显示进度条.进度详细信息的示范. 在文件上传选择界面,允许用户增加.删除选择的文件,且只能上传指定类型的 ...

  5. 使用pager进行分页

    pager jar网址:http://java2s.com/Code/Jar/t/Downloadtaglibspagejar.htm package com.binary.entity; impor ...

  6. struts2:图解action之HelloWorld示范(从action转到JSP)

    虽然Struts 2.x的Action在技术上不需要实现任何接口或继承任何类型,但是,大多情况下我们都会出于方便的原因,使Action类继承com.opensymphony.xwork2.Action ...

  7. MVC如何使用开源分页插件shenniu.pager.js

    最近比较忙,前期忙公司手机端接口项目,各种开发+调试+发布现在几乎上线无问题了:虽然公司项目忙不过在期间抽空做了两件个人觉得有意义的事情,一者使用aspnetcore开发了个人线上项目(要说线上其实只 ...

  8. [JSP]自定义标签库taglib

    自定义标签的步骤 自定义标签的步骤大概有三步: 1.继承javax.servlet.jsp.tagext.*下提供的几个标签类,如Tag.TagSupport.BodyTagSupport.Simpl ...

  9. 自己写的一个Pager分页组件,WebForm,Mvc都适用

    我一说写这个功能的时候,好多人估计有疑问.分页功能网上多的是,搜一个不就行了,你这样不是浪费时间么.你说这句话的时候,我是比较信的,首先自己写一些东西是很耗时,有这些时间又能多打几盘LOL了.但是我觉 ...

随机推荐

  1. 无法找到脚本引擎Jscript解决

    无法找到脚本引擎Jscript解决 CScript 错误: 无法找到脚本“InstallWizardForVS2010.js”的脚本引擎“JScript”. 目标环境:windows 7 64bit系 ...

  2. Android学习之路——Android四大组件之activity(二)数据的传递

    上一篇讲了activity的创建和启动,这一篇,我们来讲讲activity的数据传递 activity之间的数据传递,这里主要介绍的是activity之间简单数据的传递,直接用bundle传递基本数据 ...

  3. (转)Android 判断用户2G/3G/4G移动数据网络

    在做 Android App 的时候,为了给用户省流量,为了不激起用户的愤怒,为了更好的用户体验,是需(要根据用户当前网络情况来做一些调整的,也可以在 App 的设置模块里,让用户自己选择,在 2G ...

  4. SUN-LDAP6.3_RHEL 5.0-卸载LDAP

    卸载LDAP 1.注销服务器 到目录/ldap/ldapinstance/dscc6/bin下 # ./dsccreg remove-server -h 主机名 /ldap/ldapinstance/ ...

  5. eclipse与github建立版本关联、git使用说明

    1.在eclipse下建一个project :aa 2.打开git bush,进入aa目录下:cd /d/MyWorkspace/aa 3.git init 4.git add -A 5.git co ...

  6. <httpProtocol/>配置http协议头

    Web.Config中的位置 <configuration> <system.webServer> <httpProtocol> <!--http协议内容-- ...

  7. XAML 名称范围

    XAML 名称范围存储 XAML 定义的对象名称和它们的对等实例之间的关系.此概念类似于其他编程语言和技术中的术语名称范围的更广泛的含义. 定义 XAML 名称范围的方式 XAML 名称范围中的名称使 ...

  8. c - 比较字符串的大小

    c的标准库中当然有现成的比较字符串的函数<string.h>中的 strcmp int __cdecl strcmp(_In_z_ const char * _Str1, _In_z_ c ...

  9. scala学习笔记——类和对象

    基础语法关于Scala程序,这是非常要注意以下几点. 区分大小写 - Scala是大小写敏感的,这意味着标识Hello 和 hello在Scala中会有不同的含义. 类名 - 对于所有的类名的第一个字 ...

  10. 关于textView的字数限制

    在一个项目中遇到texteView的字数限制,在iOS7.0上,会出现崩溃.我在这里栽了一个大跟头,废话不多说,下面直接贴代码吧. - (void)textViewDidChange:(UITextV ...