1, put the pager-taglib.jar package in the project LIB;
2. Introduce the paging tag Library to the JSP page.
<% @ Taglib prefix = "PG" uri = "http://jsptags.com/tags/navigation/pager" %>
URI to copy from pager-taglib.jar \ META-INF \ taglib. TLD File
3. Specific Use
<PG: pager items = "1000">
</PG: pager>
The outermost side must be the tag, and the items is the total number of records.
<! -- The outermost side must be the pager tag, and the items is the total number of records, which are transmitted from the background. -->
<PG: pager url = "orgnization/Index" items = "$ {PM. total} "Export =" currentpagenumber = pagenumber "> // The URL is the action address, the total number of records in items, and the export can be renamed to the current page.
<PG: Param name = "parentid"/> // If parentid has a value, it will be passed behind the action as a parameter,
<PG: First>
<A href = "$ {pageurl}"> homepage </a>
</PG: First>
<PG: Prev>
<A href = "$ {pageurl}"> previous page </a> // Previous Page
</PG: Prev>
<PG: pages>
<% --
<S: If test = "% {pagenumber = currentpagenumber}">
<Font color = "red" >$ {pagenumber} </font>
</S: If>
<S: else>
<A href = "$ {pageurl}" >$ {pagenumber} </a>
</S: else>
-- %> // This section is commented out, because the test of struts2 must be specified in action for use. currentpagenumber is not specified in action, so it cannot be used; use the JSP label below to replace
<%
If (pagenumber = currentpagenumber ){
%> <Font color = "red" >$ {pagenumber} </font> <%
} Else {
%> <A href = "$ {pageurl}" >$ {pagenumber} </a> <%
}
%>
</PG: pages>
<PG: Next>
<A href = "$ {pageurl}"> next page </a> // next page
</PG: Next>
<PG: Last>
<A href = "$ {pageurl}"> last page </a>
</PG: Last>
</PG: pager>
Code in action
Public String index () throws exception {// display page
Int offset = 0; // The number of records that must be taken from the page.
If (request. getparameter ("pager. offset ")! = NULL ){
Offset = integer. parseint (request. getparameter ("pager. offset "));
}
Int pagesize = 10; // number of records per page
Long parentid = orginfo. getparentid ();
PM = orgmanager. findorgs (parentid, offset, pagesize); // PM is the pagermodel paging class, which has two attributes: Total (total number of records), list <> Datas (page result set)
If (parentid! = NULL ){
Orgnization org = orgmanager. findorg (orginfo. getparentid (); // obtain the parent institution
If (Org. getparent ()! = NULL ){
Orginfo. setppid (Org. getparent (). GETID (); // obtain the parent ID of the parent institution.
}
}
Return "Index ";
}