A class of pagination and its calling method implemented with JSP
Last Update:2017-02-28
Source: Internet
Author: User
js| page-//pagect.java-Paging class
/*
@version ***********
Created on June 25, 2001, 14:41
**************************************
*/
Package VOD;
Import java.sql.*;
Import java.util.*;
public class Pagect
{
Private long L_start; Start recording
Private long l_end; End record
Private long l_curpage; Current page
Private long l_totalnum;//total record number
private int int_num=5; 10 Records per page
Private long l_totalpage; Total number of pages
public void Init (Long currentpage,long totalnum)
{
L_curpage = CurrentPage;
L_totalnum = Totalnum;
if (currentpage>=0)
{
if (currentpage>= (long) Math.ceil (double) l_totalnum/(double) int_num)
L_curpage = (long) Math.floor (double) l_totalnum/(double) int_num);
Else
L_curpage = CurrentPage;
}
Else
{
l_curpage = 0;
}
L_start = L_curpage * INT_NUM;
L_end = L_start + int_num;
if (L_end > L_totalnum)
L_end = L_totalnum;
L_totalpage = (long) Math.ceil (double) l_totalnum/(double) int_num);
}
Public long Getcurpage ()
{
return l_curpage;
}
Public long Getprepage ()
{
if (l_curpage-1>=0)
{
return l_curpage-1;
}
Else
{
return 0;
}
}
Public long Getnextpage ()
{
if (l_curpage+1<=l_totalpage)
{
return l_curpage+1;
}
Else
{
return l_totalpage;
}
}
Public long Gettotalnum ()
{
return l_totalnum;
}
Public long Gettotalpage ()
{
return l_totalpage;
}
Public long Getstart ()
{
return l_start;
}
Public long Getend ()
{
return l_end;
}
};
===============================================
Call Example
<%
/*
@author Ma ***********
@version ***********
Created on June 12, 2001, 17:13
**************************************
*/
<%@ page import= "java.sql.*"%>
<%@ page import= "java.lang.*"%>
<%@ page contenttype= "text/html;charset=gb2312"%>
<jsp:usebean id= "PageCount" scope= "page" class= "kstest. Pagect "/>
<jsp:usebean id= "Sqlbean" scope= "page" class= "Vod.sql_data"/>
<TITLE> Test </TITLE>
<STYLE>
BODY,TABLE{FONT-SIZE:9PT}
a:link {
COLOR: #000084; Text-decoration:none
}
a:visited {
COLOR: #000084; Text-decoration:none
}
a:hover {
Color:black; Text-decoration:underline
}
. ourfont {
Font-size:9pt
}
</STYLE>
<body bgcolor= #eff3ff
<center>
<font color= #000084 > test for test </font>
<HR width=600 color= #b5dbff
<br>
<%
ResultSet Rs0 = Sqlbean.executequery ("SELECT count (*) from userlist");
Rs0.next ();
Long Data_num=rs0.getlong (1);
Long current_page = 0;
String currentpage= (String) request.getparameter ("CurrentPage");
if (currentpage!= null &&!currentpage.equals (""))
{
Current_page = Integer.parseint (Request.getparameter ("currentpage"));
}
String query_page= (String) request.getparameter ("Query_page");
if (Query_page!=null &&! Query_page.equals (""))
{
Current_page = Integer.parseint (Request.getparameter ("Query_page"))-1;
}
Pagect.init (Current_page,data_num);
Long L_start = Pagect.getstart ();
Long l_end = Pagect.getend ();
Query records
ResultSet rs = sqlbean.executequery ("SELECT * from userlist");
Long i=0;
while ((I<l_start) && Rs.next ())
{
i++;
}
Output query Results
Long j=0;
while (Rs.next () && (i<l_end))
{
j=i+1;
String col2 = rs.getstring (2);
String col3 = rs.getstring (3);
String Col4 = rs.getstring (4);
String col5 = rs.getstring (5);
String col6 = rs.getstring (6);
String col7 = rs.getstring (7);
String Col8 = rs.getstring (8);
Print the data that is displayed
Out.println ("<table border=0 width=600>");
Out.println ("<tr> <td colspan=2><font color= #000084" + j + "," + (Col2==null? "": col2) + "</font> </td> </tr> <tr> <td colspan =2> Answer: "+ (Col3==null?" ": col3) +" </td> </tr> ");
Out.println ("<tr> <td> option 1:" + (Col4==null? ": col4) + </td> <td> option 2:" + (Col5==null? ": COL5) +" </td> </tr> ");
Out.println ("<tr> <td> option 3:" + (Col6==null? ": col6) + </td> <td> Option 4:" + (Col7==null? ": COL7) +" </td> </tr> ");
if (Col8!=null &&!col8.equals (""))
{
Out.println ("<tr> <td colspan=2> Note:" +col8+ "</td> </tr>");
}
Out.println ("</table> <br>");
i++;
}
%>
<table width=600>
<TR bgcolor= #b5dbff
<form Method=get action=index.jsp>
<TD width=80 align=center valign=bottom> Total <%=pagect.gettotalnum ()%> bar </td>
<TD width=80 align=center valign=bottom><%=pagect.getcurpage () +1%>/<%=pagect.gettotalpage ()%> page </td>
<TD width=120 align=center> View <input type=text name=query_page size=3> page </td>
<TD width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=pagect.getprepage ()%>> page </a> </td>
<TD width=50 align=center valign=bottom><a href=index.jsp?currentpage=<%=pagect.getnextpage ()%>> next page </a>
</td>
</tr>
</table>
<br> <br> <br>
<table cellspacing=20>
<tr>
The <td> problem contains the <input type=text name=question_str size=10 value=<% if (question_str!= null) out.println (QUESTION_STR); %> > </td>
The <td> answer contains the <input type=text name=answer_str size=10 value=<% if (answer_str!= null) out.println (ANSWER_STR); %> > </td>
The <td> option contains the <input type=text name=sel_str size=10 value=<% if (sel!= null) OUT.PRINTLN (SEL); %> > </td>
</tr>
<tr>
<TD colspan=3 align=center><input type=submit value= Query > </td>
</tr>
</form>
</table>
<br> <br>
<a Href= "insert.jsp" to add </a>
<center>
</body>