当前位置: 技术问答>java相关
jsp中如何實現多頁顯示?
来源: 互联网 发布时间:2015-10-14
本文导语: jsp中如何實現多頁顯示? 能否給個完整的例子代碼? | 我给你一个完整的bean. package mshtang.html; /** * Title: DataBaseQuery * Description: 用于数据库翻页查询操作 * Copyright: 厦门一方软件公司版权所有Cop...
jsp中如何實現多頁顯示?
能否給個完整的例子代碼?
能否給個完整的例子代碼?
|
我给你一个完整的bean.
package mshtang.html;
/**
*
*
*
*
* @author 小唐蔡
* @version 1.0
*/
import java.sql.*;
import javax.servlet.http.*;
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 = "";
displayMessage = "";
columnNameArray = null;
columnTypeArray = null;
currentPageRecordNum = 0;
columnCount = 0;
}
/**功能:数据库初始化操作,其它操作的前提。
*
* @param conn:数据库连接;
* @param request:jsp页面request对象;
* @param querySQL:查询语句;
* @param pageSize:每页显示记录数;
* @param startPageNum:开始显示页码
*/
public void init(Connection conn, HttpServletRequest request, String querySQL, int pageSize, int startPageNum)
{
if(conn != null)
{
this.request = request;
this.sql = request.getParameter("querySQL");
this.userPara = request.getParameter("userPara");
if(sql == null || sql.equals(""))
{
sql = querySQL;
}
if(this.userPara == null)
{
this.userPara = "";
}
if(S.isContains(sql, "select;from", ";", true))
{
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
columnCount = rsmd.getColumnCount();
columnNameArray = new String[columnCount];
columnTypeArray = new String[columnCount];
String columnName;
String value;
while(rs != null && rs.next())
{
totalRecord++;
if(totalRecord == 1)
{
for(int i = 0; i 0 && pageSize > 0 && columnCount > 0 && startPageNum > 0)
{
//获取总页数
totalPages = totalRecord / pageSize;
int tempNum = totalRecord % pageSize;
if(tempNum != 0)
{
totalPages++;
}
//获得当前页页码
String currentPage = request.getParameter("currentPageNum");
currentPageNum = (currentPage == null || currentPage.equals(""))? startPageNum:Integer.parseInt(currentPage);
currentPageNum = (currentPageNum > totalPages)?totalPages:currentPageNum;
currentPageNum = (currentPageNum totalRecord)
{
currentPageRecordNum = totalRecord - (currentPageNum - 1) * pageSize;
}
else
{
currentPageRecordNum = pageSize;
}
resultArray = new String[currentPageRecordNum][columnCount];
//用于跳过前面不需显示的记录
int continueRowNum = 0;
//用于跳过后面不再显示的记录
int breakRowNum = 0;
ResultSet rs2 = st.executeQuery(sql);
while(rs2 != null && rs2.next())
{
//跳过前面不需显示的记录
continueRowNum++;
if(continueRowNum
package mshtang.html;
/**
*
Title: DataBaseQuery
*
Description: 用于数据库翻页查询操作
*
Copyright: 厦门一方软件公司版权所有Copyright (c) 2002
*
Company: 厦门一方软件公司
* @author 小唐蔡
* @version 1.0
*/
import java.sql.*;
import javax.servlet.http.*;
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 = "";
displayMessage = "";
columnNameArray = null;
columnTypeArray = null;
currentPageRecordNum = 0;
columnCount = 0;
}
/**功能:数据库初始化操作,其它操作的前提。
*
* @param conn:数据库连接;
* @param request:jsp页面request对象;
* @param querySQL:查询语句;
* @param pageSize:每页显示记录数;
* @param startPageNum:开始显示页码
*/
public void init(Connection conn, HttpServletRequest request, String querySQL, int pageSize, int startPageNum)
{
if(conn != null)
{
this.request = request;
this.sql = request.getParameter("querySQL");
this.userPara = request.getParameter("userPara");
if(sql == null || sql.equals(""))
{
sql = querySQL;
}
if(this.userPara == null)
{
this.userPara = "";
}
if(S.isContains(sql, "select;from", ";", true))
{
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
columnCount = rsmd.getColumnCount();
columnNameArray = new String[columnCount];
columnTypeArray = new String[columnCount];
String columnName;
String value;
while(rs != null && rs.next())
{
totalRecord++;
if(totalRecord == 1)
{
for(int i = 0; i 0 && pageSize > 0 && columnCount > 0 && startPageNum > 0)
{
//获取总页数
totalPages = totalRecord / pageSize;
int tempNum = totalRecord % pageSize;
if(tempNum != 0)
{
totalPages++;
}
//获得当前页页码
String currentPage = request.getParameter("currentPageNum");
currentPageNum = (currentPage == null || currentPage.equals(""))? startPageNum:Integer.parseInt(currentPage);
currentPageNum = (currentPageNum > totalPages)?totalPages:currentPageNum;
currentPageNum = (currentPageNum totalRecord)
{
currentPageRecordNum = totalRecord - (currentPageNum - 1) * pageSize;
}
else
{
currentPageRecordNum = pageSize;
}
resultArray = new String[currentPageRecordNum][columnCount];
//用于跳过前面不需显示的记录
int continueRowNum = 0;
//用于跳过后面不再显示的记录
int breakRowNum = 0;
ResultSet rs2 = st.executeQuery(sql);
while(rs2 != null && rs2.next())
{
//跳过前面不需显示的记录
continueRowNum++;
if(continueRowNum
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!
©2012-2021,