pager-taglib分页标签使用方法
主页:http://jsptags.com/tags/navigation/pager/
pager-taglib是一个JSP分页标签库
可扩展性好,需要后台JAVA分页,前台可以多种风格显示分页
缺点:没有增加样式,需要自己定义
war包可以直接运行,但是demo.jsp代码太多了
新增一个 简单的jsp ,清楚些
<%@ page session="false" %>
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg" %>
<html>
<head>
<title>Pager Tag Library Demo</title>
<style type="text/css">
A.nodec { text-decoration: none; }
</style>
</head>
<body >
<%
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);
%>
<form action="<%= request.getRequestURI() %>" method="get">
<center>
<pg:pager
items="<%= webPalette.length %>"
index="<%= index %>"
maxPageItems="<%= maxPageItems %>"
maxIndexPages="<%= maxIndexPages %>"
isOffset="<%= true %>"
export="offset,currentPageNumber=pageNumber"
scope="request">
<%-- keep track of preference --%>
<pg:param name="style"/>
<pg:param name="position"/>
<pg:param name="index"/>
<pg:param name="maxPageItems"/>
<pg:param name="maxIndexPages"/>
<%-- save pager offset during form changes --%>
<input type="hidden" name="pager.offset" value="<%= offset %>">
<%-- the pg:pager items attribute must be set to the total number of
items for index before items to work properly --%>
<table width="90%" cellspacing="4" cellpadding="4">
<%
for (int i = offset.intValue(),
l = Math.min(i + maxPageItems, webPalette.length);
i < l; i++)
{
%>
<pg:item>
<!-- 表格内容 -->
<tr>
<th><%= i + 1 %></th>
<th>AA:<%= i + 1 %></th>
</tr>
</pg:item>
<%
}
%>
</table>
<!-- 分页 -->
<br>
<pg:index>
<jsp:include page="/WEB-INF/jsp/altavista.jsp" flush="true"/>
</pg:index>
<hr>
</pg:pager>
</center>
</body>
</html>
<%!
private static final String BLACK = "#000000", WHITE = "#ffffff";
private static final String[][] webPalette = {
{ WHITE, BLACK},
{"#cccccc",BLACK},
{"#999999",BLACK},
{"#666666",WHITE},
{"#333333",WHITE},
{ BLACK, WHITE},
{"#ffcc00",BLACK},
{"#ff9900",BLACK},
{"#ff6600",BLACK},
{"#ff3300",WHITE},
{"#99cc00",BLACK},
{"#cc9900",BLACK},
{"#ffcc33",BLACK},
{"#0033ff",WHITE}
};
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;
}
%>