mysql分页怎么实现 mysql分页实现原理( 七 )


theadthTitle/ththAuthor/ththGenre/ththPublish Date/ththPrice/th/thead
tbodytr
tdspan datafld="title"/span/td
tdspan datafld="author"/span/td
tdspan datafld="genre"/span/td
tdspan datafld="publish_date"/span/td
tdspan datafld="price"/span/td
/tr
/tbody
/table
input type=button value="https://www.04ip.com/post/previous page" onclick="mytable.previousPage()"
input type=button value="https://www.04ip.com/post/next page" onclick="mytable.nextPage()"
/body
/
------------------------------------
分页显示的模板程序
!--show_page.jsp--
%@ page import="javang.*" import="java.sql.*" import="java.util.*" contentType="text/;charset=GB2312"%
%@ page import="tax.*"%
jsp:useBean id="RegisterBean" class="tax.RegisterBean" scope="page"/
jsp:useBean id="itemlist" class="tax.itemlist" scope="page"/
%
int PageSize = 10;设置一页显示的记录数
int PageNum = 1; 初始化页码=1
int PageNumCount = (136+PageSize-1) / PageSize;记算总页数
计算要显示的页码
String strPageNum = request.getParameter("page");取得href提交的页码
if(strPageNum==null){ 表明在QueryString中没有page这一个参数,此时显示第一页数据
PageNum = 1;
}
else{
PageNum = javang.Integer.parseInt(strPageNum);将字符串转换成整型
if(PageNum1) PageNum = 1;
}
if(PageNumPageNumCount) PageNum = PageNumCount;调整待显示的页码
%
head
meta -equiv="Content-Type" content="text/; charset=gb2312"
titleJSP例程 - 数据分页显示 -JDK1.2 /title
/head
body
%
if(PageNumCount0){
out.println(PageNum);显示数据,此处只简单的显示页数
}
/*需要显示的数据,在此处显示
、、、
例如:
*/
显示一个简单的表格
%
table border=1 cellspacing="0" cellpadding="0"
tr
th总数/th
th页数/th
/tr
tr
th%=PageNumCount%/th
th%=PageNum%/th
/tr
/table
第%=PageNum%页 共%=PageNumCount%页
%if(PageNumPageNumCount){%a href="https://www.04ip.com/post/show_page.jsp?page=%=PageNum+1%"下一页/a%}%
%if(PageNum1){%a href="https://www.04ip.com/post/show_page?page=%=PageNum-1%"上一页/a%}%
/body
/
---------------------------------
一个bean,按照文档说的用 。也希望你给出修改意见 。
package mshtang;
/**
* pTitle: DataBaseQuery/p
* pDescription: 用于数据库翻页查询操作/p
* pCopyright: 厦门一方软件公司版权所有Copyright (c) 2002/p
* pCompany: 厦门一方软件公司/p
* @author 小唐蔡
* @version 1.0
*/
import java.sql.*;
import javax.servlet..*;
import java.util.*;
import mshtang.StringAction;
public class DataBaseQuery
{
private HttpServletRequest request;
private StringAction S;
private String sql;
private String userPara;
private String[][] resultArray;
private String[] columnNameArray;
private String[] columnTypeArray;
private int pageSize;
private int columnCount;
private int currentPageNum;
private int currentPageRecordNum;
private int totalPages;
private int pageStartRecord;
private int totalRecord;
private static boolean initSuccessful;
private String currentJSPPageName;
private String displayMessage;
public DataBaseQuery()
{
S = new StringAction();
sql = "";
pageSize = 10;
totalRecord = 0;
initSuccessful = false;
currentJSPPageName = "";

推荐阅读