Beginner BBS page

Source: Internet
Author: User

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

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.