Final int page_size = 4;
Int pageno = 1;
String strpageno = request. getparameter ("pageno ");
If (strpageno! = NULL &&! "". Equals (strpageno. Trim ())){
Try {
Pageno = integer. parseint (strpageno );
} Catch (numberformatexception e ){
Pageno = 1;
}
}
If (pageno <= 0) pageno = 1;
Int totalpages = 0;
List <Article> articles = new arraylist <Article> ();
Connection conn = dB. getconn ();
String countsql = "select count (*) from article where pid = 0 ";
Preparedstatement pstmt = dB. getpstmt (Conn, countsql );
Resultset countrs = dB. getrs (pstmt );
Countrs. Next ();
Int totalall = countrs. getint (1 );
Totalpages = (totalall + page_size-1)/page_size;
If (pageno> totalpages) pageno = totalpages;
Int startpos = (pageNo-1) * page_size;
String SQL = "select * from article where pid = 0 order by pdate DESC limit" + startpos + "," + page_size;
Pstmt = dB. getpstmt (Conn, SQL );
Resultset rs = dB. getrs (pstmt );
While (Rs. Next ()){
Article A = new article ();
A. initfromrs (RS );
Articles. Add ();
}
DB. Close (countrs );
DB. Close (RS );
DB. Close (pstmt );
DB. Close (conn );
%>
Display
<TD> <SPAN class = "nobreak"> page:
Page <% = pageno %>, total page-<SPAN class = "jive-paginator"> [</span>
<SPAN class = "nobreak"> <SPAN class = "jive-paginator">
<A href = "articleflat. jsp? Pageno = 1 "> page 1 </a> </span>
<SPAN class = "nobreak"> <SPAN class = "jive-paginator" >|</span> </span>
<SPAN class = "nobreak"> <SPAN class = "jive-paginator">
<A href = "articleflat. jsp? Pageno = <% = pageno-1%> "> previous page </a>
</Span>
<SPAN class = "nobreak"> <SPAN class = "jive-paginator" >|</span> </span>
<SPAN class = "nobreak"> <SPAN class = "jive-paginator">
<A href = "articleflat. jsp? Pageno = <% = pageno + 1%> "> next page </a>
| & Nbsp;
<A href = "articleflat. jsp? Pageno = <% = totalpages %> "> last page </a>] </span> </TD>
Beginner BBS page