Pager: pager-taglib

Source: Internet
Author: User
Tags tld

1 introduction,
Pager-taglib supports multiple types of paging display. In fact, she is a JSP tag library. It is a set of tags designed to display paging information on JSP. Different combinations of these tags will form a variety of different paging pages, her own demo has seven paging styles, including Google's paging styles. However, it is very easy to customize the paging pages of your own style.
There are two paging methods:
One is to get a list from the action and perform automatic paging through <PG: item> on the page.
The second is to pass the pagesize and pageno parameters to the backend for database paging.
I will describe and compare the two demos:

2. Preparation
Put the pager-taglib.jar under the lib directory (this is also enough, there is no need to change the Web. xml or something in the official war package can not)

Code
<% @ Taglib uri = "http://jsptags.com/tags/navigation/pager" prefix = "PG" %>
3. jsp (the first paging scheme is divided by <PG: item> Self-Paging)

Code
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Taglib uri = "/WEB-INF/TLD/C. TLD" prefix = "C" %>
<% @ Taglib uri = "http://jsptags.com/tags/navigation/pager" prefix = "PG" %>
<HTML>
<Head> <Body>
<PG: Pager
Url = "/pageaction. Do"
Index = "half-full"
Maxpageitems = "3"
Maxindexpages = "5"
Isoffset = "<% = false %>"
Export = "pageoffset, currentpagenumber = pagenumber"
Scope = "request">

<Table>
<C: foreach items = "$ {userlist}" Var = "user">
<PG: item>
<Tr>
<TD Height = "39" >$ {user. userid} </TD>
<TD Height = "39" >$ {user. Username} </TD>
<TD Height = "39" >$ {user. Password} </TD>
</Tr>
</PG: item>
</C: foreach>
</Table>
<PG: index>
<Center>
<Table border = 0 cellpadding = 0 width = 10% cellspacing = 0>
<Tr align = center valign = top>
<TD valign = bottom> <font face = Arial, sans-serif
Size =-1> result page: </font> </TD>
<PG: Prev ifnull = "true">
<% IF (pageurl! = NULL) {%>
<TD align = right> <a href = "<% = pageurl %>"> Src = http://www.google.com/nav_previous.gif alt = "" border = 0> <br>
<B> previous </B> </a> </TD>
<%} Else {%>
<TD> </TD>
<% }%>
</PG: Prev>
<PG: pages>
<% IF (pagenumber = currentpagenumber) {%>
<TD> <br>
<Font color = # a90a08> <% = pagenumber %> </font> </TD>
<%} Else {%>
<TD> <a href = "<% = pageurl %>"> Src = http://www.google.com/nav_page.gif alt = "" border = 0> <br>
<% = Pagenumber %> </a> </TD>
<% }%>
</PG: pages>
<PG: Next ifnull = "true">
<% IF (pageurl! = NULL) {%>
<TD> <a href = "<% = pageurl %>"> Src = http://www.google.com/nav_next.gif alt = "" border = 0> <br>
<B> next </B> </a> </TD>
<%} Else {%>
<TD> </TD>
<% }%>
</PG: Next>
</Tr>
</Table>
</Center>
</PG: index>
</PG: pager>
</Body> 4. label description: several labels are used here.

1. <PG: pager> serves as a leader in this tag library, and all sub-tags work in it. The preceding parameters are described as follows:
Items: number of data records
Maxpageitems: displays the maximum number of records/Page
Maxindexpages: displays the maximum number of pages per time. If it is set to 5, this may occur: 1 2 3 4 5. or in the form of 3, 4, 5, 6, and 7, in fact, her own demo would like to display the pages in a row.
Isoffset: used together with PG: item
Export: This attribute is very important. This document also provides a relatively long description of this attribute. This attribute exposes variables to tags. Of course, these variables are optional. For example, in the pager tag, the variables that can be exposed include pageoffset and pagenumber, that is, the page number offset and page number. The two variable names can be obtained from the request in JSP or Java. The value accepted by the Export property also has an expression, such as currentpage = pagenumber, which exposes the value of pagenumber and assigns it to a variable named currentpage, which will be saved to the request, it can be obtained in JSP or Java.
Scope: cough. Do you want to talk about it?

2. The <PG: param> label is useful for setting parameters to be added to the URL. Use the name attribute. In this demo, we have passed unused parameters. In the next demo, you will see its usage.

3. The <PG: index> label indicates the content displayed in the pagination bar. Here you can set the pagination mode of various styles. In this example, it is a Google-style paging bar.
4. <PG: Prev>, <PG: pages>, <PG: Next> all these labels are navigation labels, as the name suggests. You can see them at the beginning of the example, I don't need to talk about it anymore.

V. Paging solution 2
Different from page paging, two parameters must be passed to the background,
One is pageno (current page number)
You can add & pageno = <% = pagenumber %> after each pageurl. Let our URL carry the page number parameter, so that the program can get the page number to find the required data, you can compare the two DEMO code. OK. The other parameter is pagesize, which can be found in url = "/pageaction. do? Pagesize = 5. However, the <PG> tag does not support this. It provides us with another method for passing variables. By the way, it is the label mentioned in the label description above. <PG: param>

Code
<PG: pager items = "$ {totalrows}" url = "/pageaction. do? Pagesize = 5"

In this case, the passed parameter is incorrect and should be written:

Code
<PG: pager items = "$ {totalrows}" url = "/pageaction. Do" maxindexpages = "5">
<PG: Param name = "pagesize" value = "5"/>
In addition, the <PG: param> page does not need to be called.
Then, <PG: pager> must have the items attribute.
6. The following is the Demo code.

Code
<PG: Pager
Items = "$ {totalrows }"
Url = "/pageaction. Do"
Index = "half-full"
Maxpageitems = "5"
Maxindexpages = "10" isoffset = "<% = false %>"
Export = "pageoffset, currentpagenumber = pagenumber"
Scope = "request">
<PG: Param name = "pagesize" value = "5"/>

<Table align = "center">
<C: foreach items = "$ {userlist}" Var = "user">
<! -- PG: item -->
<Tr>
<TD Height = "39" >$ {user. userid} </TD>
<TD Height = "39" >$ {user. Username} </TD>
<TD Height = "39" >$ {user. Password} </TD>
</Tr>
<! --/PG: item -->
</C: foreach>
</Table>
<PG: index>
<Center>
<Table border = 0 cellpadding = 0 width = 10% cellspacing = 0>
<Tr align = center valign = top>
<TD valign = bottom> <font face = Arial, sans-serif
Size =-1> result page: </font> </TD>
<PG: Prev ifnull = "true">
<% IF (pageurl! = NULL) {%>
<TD align = right> <a href = "<% = pageurl %> & pageno = <% = pagenumber %>"> Src = http://www.google.com/nav_previous.gif alt = "" border = 0> <br>
<B> previous </B> </a> </TD>
<%} Else {%>
<TD> </TD>
<% }%>
</PG: Prev>
<PG: pages>
<% IF (pagenumber = currentpagenumber) {%>
<TD> <br>
<Font color = # a90a08> <% = pagenumber %> </font> </TD>
<%} Else {%>
<TD> <a href = "<% = pageurl %> & pageno = <% = pagenumber %>"> Src = http://www.google.com/nav_page.gif alt = "" border = 0> <br>
<% = Pagenumber %> </a> </TD>
<% }%>
</PG: pages>
<PG: Next ifnull = "true">
<% IF (pageurl! = NULL) {%>
<TD> <a href = "<% = pageurl %> & pageno = <% = pagenumber %>"> Src = http://www.google.com/nav_next.gif alt = "" border = 0> <br>
<B> next </B> </a> </TD>
<%} Else {%>
<TD> </TD>
<% }%>
</PG: Next>
</Tr>
</Table>
</Center>
</PG: index>
</PG: pager>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.