官方 http://jsptags.com/tags/navigation/pager/index.jsp
先向 demo 页面样式:
########################################################################################
request.getParameter 中参数
'pager.offset'=6
分页中标签中隐含属性 'offset'=6
|< << 12 34567 >> >|
|< << 12
34567 >> >|
#######################################################################################
<!-- 分页具体表现页面 -->
先向 demo 页面样式:
########################################################################################
request.getParameter 中参数
'pager.offset'=6
分页中标签中隐含属性 'offset'=6
|< << 12 34567 >> >|
7 |
---|
8 |
9 |
#######################################################################################
<%
@ page session
=
"
false
"
%>
<% @ taglib uri = " http://jsptags.com/tags/navigation/pager " prefix = " pg " %>
<% @ page contentType = " text/html; charset=gb2312 " %>
< html >
< head >
< title > Pager Tag Library Demo </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
<!-- 参数展现 -->
request.getParameter 中参数 < br />
<% for ( Object otmp : request.getParameterMap().keySet() ){ %>
<% = " ' " + otmp.toString() + " ' " %> = <% = request.getParameter(otmp.toString()) %> < br \ >
<% } %>
< form action ="<%= request.getRequestURI() %>" method ="get" >
< br />
<!--
items=数据总条??
index=分页标明展现格式;"center", "forward" or "half-full".
maxPageItems=每页最大展现行数;
maxIndexPages=每页最大可选页数;
isOffset=数据是否展现;
scope=参数作用范围;
-->
< pg:pager
items ="<%= webPalette.length %>"
index ="<%= " center" % > "
maxPageItems=" <% = 3 %> "
maxIndexPages=" <% = 10 %> "
isOffset=" <% = true %> "
export="offset,currentPageNumber=pageNumber"
scope="request">
< br /> 分页中标签中隐含属性 'offset'= <% = offset %> < br />
<!--
分页需要向下传递的参数;
比如组合查询使用参数.
此为get提交;乱码问题特别注意;
如:parameter(google) 参数由本页面传递给下一分页页面;
-->
< pg:param name ="google" />
<!-- 分页具体表现页面 -->
< pg:index >
< jsp:include page ="/WEB-INF/jsp/texticon.jsp" flush ="true" />
</ pg:index >
< hr >
< table width ="90%" cellspacing ="4" cellpadding ="4" >
<% for ( int i = offset.intValue(),l = Math.min(i + 10 , webPalette.length);i < l; i ++ ){ %>
< pg:item >
< tr >< th bgcolor ="<%= webPalette[i][0] %>" >< font color ="<%= webPalette[i][1] %>" > <% = i + 1 %> </ font ></ th ></ tr >
</ pg:item >
<% } %>
</ table >
< hr >
< pg:index >
< jsp:include page ="/WEB-INF/jsp/texticon.jsp" flush ="true" />
</ pg:index >
</ 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},
{ " #ffcc66 " ,BLACK},
{ " #ff9966 " ,BLACK},
{ " #ff6633 " ,BLACK},
{ " #cc3300 " ,WHITE},
{ " #cc0033 " ,WHITE},
{ " #ccff00 " ,BLACK},
{ " #ccff33 " ,BLACK},
{ " #333300 " ,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;
}
%>
<% @ taglib uri = " http://jsptags.com/tags/navigation/pager " prefix = " pg " %>
<% @ page contentType = " text/html; charset=gb2312 " %>
< html >
< head >
< title > Pager Tag Library Demo </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
<!-- 参数展现 -->
request.getParameter 中参数 < br />
<% for ( Object otmp : request.getParameterMap().keySet() ){ %>
<% = " ' " + otmp.toString() + " ' " %> = <% = request.getParameter(otmp.toString()) %> < br \ >
<% } %>
< form action ="<%= request.getRequestURI() %>" method ="get" >
< br />
<!--
items=数据总条??
index=分页标明展现格式;"center", "forward" or "half-full".
maxPageItems=每页最大展现行数;
maxIndexPages=每页最大可选页数;
isOffset=数据是否展现;
scope=参数作用范围;
-->
< pg:pager
items ="<%= webPalette.length %>"
index ="<%= " center" % > "
maxPageItems=" <% = 3 %> "
maxIndexPages=" <% = 10 %> "
isOffset=" <% = true %> "
export="offset,currentPageNumber=pageNumber"
scope="request">
< br /> 分页中标签中隐含属性 'offset'= <% = offset %> < br />
<!--
分页需要向下传递的参数;
比如组合查询使用参数.
此为get提交;乱码问题特别注意;
如:parameter(google) 参数由本页面传递给下一分页页面;
-->
< pg:param name ="google" />
<!-- 分页具体表现页面 -->
< pg:index >
< jsp:include page ="/WEB-INF/jsp/texticon.jsp" flush ="true" />
</ pg:index >
< hr >
< table width ="90%" cellspacing ="4" cellpadding ="4" >
<% for ( int i = offset.intValue(),l = Math.min(i + 10 , webPalette.length);i < l; i ++ ){ %>
< pg:item >
< tr >< th bgcolor ="<%= webPalette[i][0] %>" >< font color ="<%= webPalette[i][1] %>" > <% = i + 1 %> </ font ></ th ></ tr >
</ pg:item >
<% } %>
</ table >
< hr >
< pg:index >
< jsp:include page ="/WEB-INF/jsp/texticon.jsp" flush ="true" />
</ pg:index >
</ 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},
{ " #ffcc66 " ,BLACK},
{ " #ff9966 " ,BLACK},
{ " #ff6633 " ,BLACK},
{ " #cc3300 " ,WHITE},
{ " #cc0033 " ,WHITE},
{ " #ccff00 " ,BLACK},
{ " #ccff33 " ,BLACK},
{ " #333300 " ,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;
}
%>
<!-- 分页具体表现页面 -->
<%
@ 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 >
<!-- 每次后退跳10页 -->
< pg:skip export ="skipBackPageUrl=pageUrl" pages ="<%= -10 %>" >
< a href ="<%= skipBackPageUrl %>" > <<< </ a >
</ pg:skip >
<!-- 每次后退跳 1 页 -->
< 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 >
<!-- 每次前进跳 1 页 -->
< pg:next export ="nextPageUrl=pageUrl" >
< a href ="<%= nextPageUrl %>" > >> </ a >
</ pg:next >
<!-- 每次后前进10页 -->
< 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 >
<% @ 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 >
<!-- 每次后退跳10页 -->
< pg:skip export ="skipBackPageUrl=pageUrl" pages ="<%= -10 %>" >
< a href ="<%= skipBackPageUrl %>" > <<< </ a >
</ pg:skip >
<!-- 每次后退跳 1 页 -->
< 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 >
<!-- 每次前进跳 1 页 -->
< pg:next export ="nextPageUrl=pageUrl" >
< a href ="<%= nextPageUrl %>" > >> </ a >
</ pg:next >
<!-- 每次后前进10页 -->
< 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 >