This is the paging code in our project. It is implemented using jstl + custom tag file + JavaBean. It may be helpful to you:
1. Custom Tag file
1. iterator. Tag
<! -- Standard tag and custom tag declaration -->
<! -- Undeclared attributes are supported -->
<% @ Tag dynamic-attributes = "attributes" %>
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %>
<% @ Taglib prefix = "FN" uri = "http://java.sun.com/jsp/jstl/functions" %>
<! -- Declare the property value -->
<! -- Data: The data to be processed. It is of the list type. -->
<! -- Rows: number of lines displayed per page -->
<! -- Current page number -->
<! -- Whether ispagination displays paging information -->
<! -- Background color of the trbgcolor table -->
<! -- Info_list JSP action attribute call value -->
<! -- Var data transmission Attributes -->
<! -- Current data transmission attributes fixed names are aliases -->
<% @ Attribute name = "data" required = "true" type = "Java. util. List" %>
<% @ Attribute name = "rows" %>
<% @ Attribute name = "page" %>
<% @ Attribute name = "ispagination" %>
<% @ Attribute name = "trbgcolor" %>
<% @ Attribute name = "info_list" fragment = "true" required = "true" %>
<% @ Attribute name = "Var" rtexprvalue = "false" required = "true" %>
<% @ Variable name-from-attribute = "Var" alias = "current" variable-class = "Java. Lang. Object" Scope = "nested" %>
<! -- Set the default value -->
<! -- Rows = 10: 10 rows are displayed on each page by default -->
<! -- Page = 1: the first page is displayed by default -->
<! -- Trbgcolor = white: the Default background color of a table is colorless. -->
<C: Set Var = "rows" value = "$ {empty rows? 10: rows} "/>
<C: Set Var = "page" value = "$ {empty page? 1: Page} "/>
<C: Set Var = "trbgcolor" value = "$ {empty trbgcolor? '': Trbgcolor}"/>
<! -- Initialize paging-related data -->
<! -- Data to be processed -->
<! -- Perpagerows: number of lines displayed per page -->
<! -- Currentpage current page -->
<C: If test = "$ {! Empty ispagination} ">
<JSP: usebean id = "pagination" class = "com. winmess. Japanese. util. pagination"/>
<C: set target = "$ {pagination}" property = "data" value = "$ {data}"/>
<C: set target = "$ {pagination}" property = "perpagerows" value = "$ {rows}"/>
<C: set target = "$ {pagination}" property = "currentpage" value = "$ {page}"/>
</C: If>
<C: Set Var = "beginrow" value = "$ {empty pagination. currentrow? 0: pagination. currentrow} "/>
<C: Set Var = "endrow" value = "$ {empty pagination. lastrow? (Rows-1): pagination. lastrow} "/>
<! -- Display content -->
<Table width = "100%" cellspacing = "0" cellpadding = "0" border = "0">
<Tr>
<TD>
<Table
<C: foreach items = "$ {attributes}" Var = "A">
$ {A. Key} = "$ {A. Value }"
</C: foreach>
>
<Form name = "infolistform" method = "Post" Action = "">
<! -- Information iteration -->
<C: foreach items = "$ {data}" Var = "current" begin = "$ {beginrow}" End = "$ {endrow}">
<Tr bgcolor = "$ {trbgcolor}">
<! -- Action display (the actions on the JSP page will be displayed here) -->
<JSP: invoke fragment = "info_list"/>
</Tr>
</C: foreach>
</Form>
</Table>
</TD>
</Tr>
<! -- Display information by page -->
<C: If test = "$ {! Empty ispagination} ">
<Tr> <TD>
<Table width = "100%" Height = "80%">
<Form name = "turnpageform" method = "Post" Action = "">
<Tr>
<JSP: usebean id = "prompt" class = "com. winmess. Japanese. util. paginationprompt"/>
& Lt; TD width = "50%" & gt;
& Nbsp;
$ {Prompt. Total }$ {pagination. totalrows }$ {prompt. Record}
& Nbsp;
$ {Pagination. currentpage}/$ {pagination. totalpages }$ {prompt. pageprompt}
</TD>
& Lt; TD width = "50%" align = "right" & gt;
<A href = "<C: URL value =" $ {requesturl }? Page = 1 & classname =$ {classname} & sort =$ {sort} "/>" >$ {prompt. firstpage} </a>
<A href = "<C: URL value =" $ {requesturl }? Page =$ {pagination. currentpage-1} & classname =$ {classname} & sort =$ {sort} "/>" >$ {prompt. prepage} </a>
<A href = "<C: URL value =" $ {requesturl }? Page =$ {pagination. currentpage + 1} & classname =$ {classname} & sort =$ {sort} "/>" >$ {prompt. nextpage} </a>
<A href = "<C: URL value =" $ {requesturl }? Page =$ {pagination. totalpages} & classname =$ {classname} & sort =$ {sort} "/>" >$ {prompt. lastpage} </a>
<! -- Number of pages displayed in the drop-down list -->
<Select name = "jumppage" size = "1" onchange = "javascript: Location = '$ {requesturl }? Page = '+ this. Options [This. selectedindex]. Value +' & classname =$ {classname} & sort =$ {sort} '; ">
<C: foreach begin = "1" End = "$ {pagination. totalpages}" Var = "I">
<Option value = "$ {I}" $ {I = pagination. currentpage? "Selected": ""}>
$ {I}
</Option>
</C: foreach>
</Select >$ {prompt. Page}
</TD>
</Tr>
</Form>
</Table>
</TD>
</Tr>
</C: If>
</Table>
2. Param. Tag
<! -- Standard tag and custom tag declaration -->
<! -- Undeclared attributes are supported -->
<% @ Tag dynamic-attributes = "attributes" %>
<% @ Taglib prefix = "FN" uri = "http://java.sun.com/jsp/jstl/functions" %>
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %>
<! -- Declare the property value -->
<! -- Name: data to be processed -->
<! -- Name1 data to be processed 2 -->
<! -- Length: the length of each piece of information displayed -->
<! -- What page does the URL link to -->
<! -- What is the align table house display? -->
<! -- IMG loads the image address -->
<! -- Checkout load multiple selection boxes -->
<% @ Attribute name = "name" %>
<% @ Attribute name = "name1" %>
<% @ Attribute name = "length" %>
<% @ Attribute name = "url" %>
<% @ Attribute name = "align" %>
<% @ Attribute name = "IMG" %>
<% @ Attribute name = "checkbox" %>
<% @ Attribute name = "target" %>
<! -- Set the default value -->
<! -- Length = 50 the default length of each message is 50 -->
<! -- Align = the center table is displayed in the center by default. -->
<! -- Name1 data to be processed 2 -->
<C: Set Var = "length" value = "$ {empty length? 50: length} "/>
<C: Set Var = "align" value = "$ {empty align? 'Left': Align} "/>
<C: Set Var = "name1" value = "$ {empty name1? '': Name1}"/>
<C: Set Var = "target" value = "$ {empty Target? '_ Blank': ''}"/>
<! -- Display content -->
<TD
<C: foreach items = "$ {attributes}" Var = "A">
$ {A. Key} = "$ {A. Value }"
</C: foreach>
>
<C: If test = "$ {checkbox = 'true'}">
<Input type = "checkbox" name = "are" value = "OK"/>
</C: If>
<C: Set Var = "checktitle" value = "$ {empty FN: substring (name, length, Length + 20)}"/>
<C: Choose>
<C: When test = "$ {empty URL}">
<Div align = "$ {Align}">
<Font size = "2.5"> <C: Out value = "$ {fn: substring (name, 0, length)}"/> </font>
$ {Checktitle? "":"..."}
<Font size = "2.5"> <C: Out value = "$ {name1}"/> </font>
</Div>
</C: When>
<C: otherwise>
<A href = "$ {URL}" target = "$ {target}">
<Div align = "$ {Align}">
<Font size = "2.5"> <C: Out value = "$ {fn: substring (name, 0, length)}"/> </font>
$ {Checktitle? '':"..."}
<Font size = "2.5"> <C: Out value = "$ {name1}"/> </font>
</Div>
</A>
</C: otherwise>
</C: Choose>
<C: If test = "$ {! Empty IMG} ">
</C: If>
</TD>
Put the first two markup files in/WEB-INF/tags/mytags
Ii. JavaBean
1. pagination. Java
/*
* @ Date 2005-2-18
* @ Project japaneseindalian
* @ Company winmess
* @ Version 1.2
*/
Package com. winmess. Japan. util;
Import java. util. List;
/**
* @ Author chanson
* @ Description: Basic paging class
*/
Public class pagination {
Private list data; // number of records
Private int totalrows; // The total number of rows.
Private int perpagerows; // number of rows per page
Private int totalpages; // the total number of pages.
Private int currentpage; // current page
Private int currentrow; // The current row.
Private int lastrow; // tail row
/**
* Default constructor
*/
Public pagination (){
Super ();
}
/**
* Calculate the respective values based on data, perpagerows, and currentpage.
* @ Param list
* @ Param perpagerows
* @ Param currentpage
*/
Public void reckon (){
/**
* Value setting
*/
This. totalrows = data. Size (); // total number of rows
This. perpagerows = perpagerows <1? 10: perpagerows; // The number of rows per page. The default value is 10.
This. totalpages = totalrows/perpagerows + 1; // total number of pages
If (totalrows % perpagerows = 0) & (totalrows! = 0 )){
This. totalpages = This. totalpages-1;
}
This. currentpage = currentpage <1? 1: currentpage; // current page number. The default value is 1st.
// When the current page exceeds the maximum page, the current page is set to the maximum page
This. currentpage = currentpage> totalpages? Totalpages: currentpage;
This. currentrow = (currentpage-1) * perpagerows; // The row starting with the current
This. lastrow = currentrow + perpagerows-1; // The end row.
}
Public list getdata (){
Return data;
}
Public void setdata (List data ){
This. Data = data;
}
Public int getlastrow (){
Return lastrow;
}
Public void setlastrow (INT lastrow ){
This. lastrow = lastrow;
}
Public int getcurrentpage (){
Return currentpage;
}
Public void setcurrentpage (INT currentpage ){
This. currentpage = currentpage;
Reckon ();
}
Public int getcurrentrow (){
Return currentrow;
}
Public void setcurrentrow (INT currentrow ){
This. currentrow = currentrow;
}
Public int getperpagerows (){
Return perpagerows;
}
Public void setperpagerows (INT perpagerows ){
This. perpagerows = perpagerows;
}
Public int gettotalpages (){
Return totalpages;
}
Public void settotalpages (INT totalpages ){
This. totalpages = totalpages;
}
Public int gettotalrows (){
Return totalrows;
}
Public void settotalrows (INT totalrows ){
This. totalrows = totalrows;
}
}///:~
2. paginationprompt. Java
/*
* @ Date 2005-3-18
* @ Project japaneseindalian
* @ Company winmess
* @ Version 1.2
*/
Package com. winmess. Japan. util;
Import java. Io. unsupportedencodingexception;
/**
* @ Author chanson
*
*/
Public class paginationprompt {
Private string firstpage = "latest"; // Home Page
Private string lastpage = "first"; // the last page.
Private string prepage = "prefix"; // Previous Page
Private string nextpage = "へ"; // next page
Private string page = "your website has been successfully created"; // the page to which you want to jump.
Private string pageprompt = "ページ"; // page prompt: ページを
Private string Total = "sum:"; // total
Private string record = "pieces"; // Several Records
Public String getfirstpage () throws unsupportedencodingexception {
Firstpage = new string (firstpage. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return firstpage;
}
Public String gettotal () throws unsupportedencodingexception {
Total = new string (total. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return total;
}
Public String getlastpage () throws unsupportedencodingexception {
Lastpage = new string (lastpage. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return lastpage;
}
Public String getnextpage () throws unsupportedencodingexception {
Nextpage = new string (nextpage. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return nextpage;
}
Public String getpage () throws unsupportedencodingexception {
Page = new string (page. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return page;
}
Public String getpageprompt () throws unsupportedencodingexception {
Pageprompt = new string (pageprompt. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return pageprompt;
}
Public String getprepage () throws unsupportedencodingexception {
Prepage = new string (prepage. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return prepage;
}
Public String getrecord () throws unsupportedencodingexception {
Record = new string (record. getbytes ("shift-JIS"), "ISO-8859-1 ");
Return record;
}
}
3. Call
1. Statement
<% @ Taglib prefix = "my" tagdir = "/WEB-INF/tags/mytags" %>
2. Use
<% @ Attribute name = "align" %>
<% @ Attribute name = "info_list" fragment = "true" required = "true" %>
<My: iterator DATA = "$ {list}" page = "$ {current_page}" Var = "current" border = "1" ispagination = "true" align = "center">
<JSP: attribute name = "info_list">
<My: Param name = "$ {current. ID}" width = "4"/>
<My: Param name = "$ {current. callnumber}" width = "10" length = "6" url = "... $ {requesturi}"/>
<My: Param name = "$ {current. booktype}" width = "10"/>
<My: Param name = "$ {current. bookid}" width = "6"/>
<My: Param name = "$ {current. bookname}" width = "10"/>
<My: Param name = "$ {current. innumber}" width = "5"/>
<My: Param name = "$ {current. bookauthor}" width = "8"/>
<My: Param name = "$ {current. bookpublisher}" width = "10"/>
<My: Param name = "$ {current. bookeditionorder}" width = "10"/>
<My: Param name = "$ {current. bookeditionorder}" width = "10"/>
<My: Param name = "$ {current. bookprice}" width = "10"/>
<My: Param name = "$ {current. bookparenthesis}" width = "5"/>
</Jsp: attribute>
</My: iterator>