Pagination Using jsp

Source: Internet
Author: User

Use jsp to achieve the most basic page flip:

<% @ Page import = "java. util. arrayList "%> <% @ page import =" serchJava. trssearcher. articleBean "%> <% @ page import =" java. util. list "%> <% @ page language =" java "contentType =" text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ page session =" true "%> <% @ page errorPage =" error. jsp "%>
 Search<Script type = "text/javascript"> function validate1 () {var page = document. forms [0]. page. value; if (page. length <= 0) {alert ("Enter the number of pages to jump! ");} Else if (isNaN (page) {alert (" enter a valid page number! ") ;}Else {document. forms [0]. submit () ;}}</script>
 
 
 
 <% String str = request. getParameter ("keyWords"); String strWhere = "Title =" + str + "or body =" + str; int intPage = 0; // page number to be displayed // obtain the page number to be displayed String strPage = request. getParameter ("page"); if (strPage = null) // indicates that the page parameter is not found in QueryString, and the first page of data is displayed {intPage = 1 ;} else {intPage = java. lang. integer. parseInt (strPage); if (intPage <1) {intPage = 1 ;}} sResult = searchBean. searchList (strWhere, intPage); int intRowCount = (int) sResult. getTotal (); out. println ("Retrieval time:" + sResult. getCosttime () +"
"); Out. println (" Total number of records: "+ intRowCount +"
"+"
"); Int PgFirst = (intPage-1) * 20 + 1; // The first entry of the number of pages to be displayed List articleList = sResult. getArticleBeans (); // get the title list object int intPageCount = sResult. getPageNum (); // obtain the total number of pages for (int I = 0; I <articleList. size (); I ++) {ArticleBean article = new ArticleBean (); article = articleList. get (I); String strTitle = article. getTitle (); String rowid = article. getRowid (); out. println ("no." + PgFirst + ":" +"
"); %> Title:"> <% = strTitle %> <% out. println ("
"+" Date: "+ article. getDate () +"
"); PgFirst ++ ;}%>
<% = IntPage %> page/total <% = intPageCount %> page total <% = intRowCount %> records <% if (intPage <2) {out. print ("homepage | previous page ");} else {%> & keyWords = <% = str %> "> homepage | & keyWords = <% = str %>"> previous page <% }%> | <% if (( intPageCount-intPage) <1) {out. print ("next page | last page ");} else {%> & keyWords = <% = str %> "> next page | & keyWords = <% = str %>"> last page <%} %>

Can refer to the use of jstl after the effect, http://blog.csdn.net/redeagle_gbf/article/details/17168131
Compared with jstl, it is found that the amount of code used and the use effect are much better.

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.