Example of simplified JSP pager tag

Source: Internet
Author: User
Tags tld

<% @ Page Language = "Java" contenttype = "text/html; charset = GBK" %>
<% @ Taglib uri = "/WEB-INF/struts-html.tld" prefix = "html" %>
<% @ Taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic" %>
<% @ Taglib uri = "/WEB-INF/struts-bean.tld" prefix = "Bean" %>
<% @ Taglib uri = "/WEB-INF/pager-taglib.tld" prefix = "PG" %>
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %>
<% @ Taglib prefix = "FMT" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<% @ Taglib prefix = "display" uri = "http://displaytag.sourceforge.net/" %>
<% @ Taglib uri = "/TLD/extremecomponents" prefix = "EC" %>
<% @ Page import = "displaytag. testlist, java. util. List" %>
<LINK rel = "stylesheet" type = "text/CSS" href = "<C: URL value ="/CSS/mycss.css "/>">
<% --
This is an example of JSP pager tag.
The example is very simple. It can be seen that the amount of code that uses JSP pager tag to implement pagination is very small.
 
<PG: pager items = "$ {resultsize}" // total number of results
Maxpageitems = "<% = 5%>" // The majority of each page
Maxindexpages = "<% = 5%>" // index display count
Isoffset = "<% = true %>" // set to true.
Url = "/jsppager. jsp" // The action executed by the dot Link
Export = "offset, currentpagenumber = pagenumber" // generate a local variable, which is generally the deviation amount and current page number
Scope = "request"
>
The data transmitted here to the tag includes:
1. Total number of pages
2. Number of records per page
3. Number of Indexes
4. The action executed by the vertex Index
Outgoing data includes:
1, offset
2. Current page number


<PG: Page export = "firstitem, lastitem"> // output the first subscript and the last subscript of the current page.
This label indicates the information of the current page.

The index page can be changed a lot. It mainly refers to the offset calculated by the tag.

For the convenience of testing, the corresponding action on this page is your own. The actual project can use action,

The task of action is
1. the offset of the received record set (pager. offset), the maximum number of records per page.
2. Get a set of records on one page based on the above two data. And send it to the page.
3. Total number of downstream records.

Page task:
1. initialize the JSP page tag based on the total number of downloads.
2. display the next set. (displaytag is used in this example)
-- %>
<%
String foffset = request. getparameter ("pager. offset ");
Int ioffset = integer. parseint (foffset );
List list = new testlist (40, false );
List sublist = List. sublist (ioffset, ioffset + 5 );
Request. setattribute ("u2bmanpointlist", sublist );
Request. setattribute ("resultsize", "40 ");
%>
<Table width = 760 border = 0 align = center cellpadding = 0 cellspacing = 0>
<Tr>
<TD width = "704" Height = "300" align = "right">

<PG: pager items = "$ {resultsize }"
Maxpageitems = "<%= 5%>"
Maxindexpages = "<%= 5%>"
Isoffset = "<% = true %>"
Url = "/jsppager. jsp"
Export = "offset, currentpagenumber = pagenumber"
Scope = "request"
>
<PG: Page export = "firstitem, lastitem">
<Div class = "resultinfo">
Current page number: <strong >$ {currentpagenumber} </strong>,
This page starts from <strong> <% = firstitem %> </strong>
To <strong> <% = lastitem %> </strong>
Total number of records <strong >$ {resultsize} </strong>
</Div>
</PG: Page>
 

<Display: Table width = "100%" Height = "10" id = "myitem" name = "u2bmanpointlist" class = "report">
<Display: column width = "20%" sortable = "true" Title = "name" >$ {myitem. name} </display: column>
</Display: Table>
 
<JSP: Include page = "/Google. jsp" Flush = "true"/> <br>
<% --
<JSP: Include page = "/alltheweb. jsp" Flush = "true"/> <br>
<JSP: Include page = "/Yahoo. jsp" Flush = "true"/> <br>
<JSP: Include page = "/Altavista. jsp" Flush = "true"/> <br>
<JSP: Include page = "/Lycos. jsp" Flush = "true"/> <br>
<JSP: Include page = "/texticon. jsp" Flush = "true"/> <br>
<JSP: Include page = "/simple. jsp" Flush = "true"/> <br>
-- %>
</Div> </TD>
</PG: pager>
</Table>
========================================================== ======================================

Note: testlist is a list with a listobject object in it.

 

Related Article

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.