When a large number of data is listed, the screen cannot be fully displayed, you must use pagination, SQL paging has been discussed in other articles, here is the implementation of JSP Division code.
Page incoming parameter P as page selection, no parameter default first page.
Calculate the basic parameters of the page division, currentpage for the current page, PageRows set the number of rows per page, in the acquisition of Totalpage is total pages, the actual situation according to the data of the decision, here tentatively 4000.
Paging Parameters
Default current page number 0
long currentpage = 0;
If the incoming argument p is valid, fetch the incoming argument
if (Request.getparameter ("P")!= null)
{
//Get the current page parameter
String p = Request.getparameter ("P");
Try
{
//Get number of pages of numeric type
currentpage = long.valueof (P);
}
catch (Exception e)
{
currentpage = 0;
}
}
The total number of records (for example, taken from the database)
long = 4000;
Set the number of rows per page
final long pagerows =;
List 9 pages with current page not centered
final int clickpagelist = 9;
Calculates the number of pages with PageRows as line number
long PageCount = total% PageRows;
If the remainder is greater than 0 it must be under the total page + 1
if (PageCount > 0)
{
//Get the actual page number
PageCount = total/pagerows + 1;
}
Else
{
PageCount = total/pagerows;
}
Paging Implementation
// If the number of pages is valid
If (pageCount > 0)
{
// Set two fixed links for easy operation
If (currentPage > 0)
{
Out.print(String.format("<A href=\"page.jsp?p=%s\" target=_blank>Previous</A> ", currentPage - 1));
}
Else
{
Out.print("previous page");
}
If (currentPage < pageCount - 1)
{
Out.print(String.format("<A href=\"page.jsp?p=%s\" target=_blank> Next page</A> ", currentPage + 1));
}
Else
{
Out.print("Next");
}
Out.print("<a href=\"page.jsp\"> Page 1</a> ");
String line = "";
// List the link to the left of the current page
For (long i = currentPage; i >= 0; i--)
{
// limit the number listed to the left
If (i < (currentPage - clickPageList))
{
Break;
}
Line = String.format("<a href=\"page.jsp?p=%s\">%s</a> ", i, i + 1) + line;
}
Out.print(line);
Line = "";
// List the link to the right of the current page
For (long i = currentPage + 1; i <= pageCount - 1; i++)
{
// limit and list the quantity
If (i >= (currentPage + clickPageList))
{
Break;
}
Line = line + String.format("<a href=\"page.jsp?p=%s\">%s</a> ", i, i + 1);
}
Out.print(line);
Line = "";
Out.print(String.format("<a href=\"page.jsp?p=%s\">last page</a>", pageCount - 1));
}
The page selection code is as follows:
The demo effect is as follows, the actual use can replace the text with the corresponding picture or CSS style, in order to achieve better results