Posted on 2008-01-29 15:57
G_G 阅读(1520)
评论(0) 编辑 收藏 所属分类:
JspTag
使用:pager-taglib-2.0
官方:http://jsptags.com/tags/navigation/pager
使用页面:
<%@ taglib prefix="pg" uri="/WEB-INF/pager-taglib.tld" %>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'pg.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<%!
private static final String getParam(ServletRequest request, String name,
String defval)
{
String param = request.getParameter(name);
return (param != null ? param : defval);
}
private static final int getParam(ServletRequest request, String name,
int defval)
{
String param = request.getParameter(name);
int value = defval;
if (param != null) {
try { value = Integer.parseInt(param); }
catch (NumberFormatException ignore) { }
}
return value;
}
%><%
String style = getParam(request,"style", "simple");
String position = getParam(request, "position", "top");
String index = getParam(request, "index", "center");
int maxPageItems = getParam(request, "maxPageItems", 10);
int maxIndexPages = getParam(request, "maxIndexPages", 10);
List list = new ArrayList();
for(int i=0;i<1000;i++){
list.add(i);
} %>
</head>
<body>
<form action="<%= request.getRequestURI() %>" method="get">
<center>
<pg:pager
items="<%= list.size() %>"
index="<%= index %>"
maxPageItems="<%= maxPageItems %>"
maxIndexPages="<%= maxIndexPages %>"
isOffset="<%= true %>"
export="offset,currentPageNumber=pageNumber"
scope="request">
<pg:index>
<!-- 引用标签页面 -->
<jsp:include page="../jsp/texticon.jsp" flush="true"/>
</pg:index>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
<hr>
<table width="90%" cellspacing="4" cellpadding="4">
<!-- 这里参数 l为结尾数 i->offset.intValue() 起点数 -->
<%for (int i = offset.intValue(),
l = Math.min(i + maxPageItems, list.size());
i < l; i++)
{%>
<pg:item>
<tr>
<th>
<font color="<%= list.get(i) %>"><%= i + 1 %></font>
</th>
</tr>
</pg:item>
<%}%>
</table>
<hr>
</pg:pager>
</body>
</html>
定义分页标签样式页:
<%@ page session="false" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<jsp:useBean id="currentPageNumber" type="java.lang.Integer" scope="request"/>
<font face="fixed">
<pg:first export="firstPageUrl=pageUrl" unless="current">
<a href="<%= firstPageUrl %>">|<</a>
</pg:first>
<pg:skip export="skipBackPageUrl=pageUrl" pages="<%= -10 %>">
<a href="<%= skipBackPageUrl %>"><<<</a>
</pg:skip>
<pg:prev export="prevPageUrl=pageUrl">
<a href="<%= prevPageUrl %>"><<</a>
</pg:prev>
<pg:pages><%
if (pageNumber == currentPageNumber) {
%> <b><%= pageNumber %></b> <%
} else {
%> <a href="<%= pageUrl %>"><%= pageNumber %></a> <%
}
%></pg:pages>
<pg:next export="nextPageUrl=pageUrl">
<a href="<%= nextPageUrl %>">>></a>
</pg:next>
<pg:skip export="skipForwardPageUrl=pageUrl" pages="<%= 10 %>">
<a href="<%= skipForwardPageUrl %>">>>></a>
</pg:skip>
<pg:last export="lastPageUrl=pageUrl" unless="current">
<a href="<%= lastPageUrl %>">>|</a>
</pg:last>
</font>