<%
//变量声明
java.sql.Connection sqlCon; //数据库连接对象
java.sql.Statement sqlStmt; //SQL语句对象
java.sql.ResultSet sqlRst; //结果集对象
java.lang.String strCon; //数据库连接字符串
java.lang.String strSQL; //SQL语句
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
int layer;
int idlayer;
idlayer=1;
java.lang.String outtext;
outtext="";
java.lang.String strPage;
int j;
int i;
//设置一页显示的记录数
intPageSize = 10;
//取得待显示页码
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
//装载JDBC驱动程序
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//连接数据库
sqlCon = java.sql.DriverManager.getConnection("jdbc:mysql://218.22.156.3/kjeny_db","kjeny","cdgame");
//创建语句对象
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//执行SQL语句并获取结果集
sqlRst = sqlStmt.executeQuery("SELECT * FROM dxswlxh");
//获取记录总数
sqlRst.last();
intRowCount = sqlRst.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base target="contents">
<LINK rel="stylesheet" href="css.css">
<script language="JavaScript">
function byteLen(str) {
var iByteLen = 0;
if (str == null || str == "") {
iByteLen = 0;
} else {
for (var i = 0; i < str.length; i++) {
if(str.charCodeAt(i) < 0x80) {
iByteLen++;
} else {
iByteLen += 2;
}
}
}
return iByteLen;
}
</script>
</head>
<body topmargin="0" leftmargin="0" bgcolor=ccffcc>
<table width="100%"><tr><td bgcolor="ff66cc">
>> 分页
<form method=post action="pink.jsp?page=1" target=ttop>
<input type=submit value="首 页">
</form>
<%if(intPage>1){
%>
<form method=post action="pink.jsp?page=<%=intPage-1%>" target=ttop>
<input type=submit value=上一页>
</form>
<%}%>
<%if(intPage<intPageCount)
{%>
<form method=post action="pink.jsp?page=<%=intPage+1%>" target=ttop>
<input type=submit value=下一页>
</form>
<%}%>
<form method=post action="pink.jsp?page=<%=intPageCount%>" target=ttop>
<input type=submit value="尾 页">
</form>
页次:<%=intPage%>/<%=intPageCount%>页 <%=intPageSize%>条/页
</td></tr></table>
<table>
<td width="%100"><ul><%
if(intPageCount>0){
sqlRst.absolute((intPage-1) * intPageSize + 1);
i = 0;
while(i<intPageSize && !sqlRst.isAfterLast()){
String names = sqlRst.getString(3);
String use_xi = sqlRst.getString(4);
%>
<li><%=names%> - 【<%=use_xi%>】
<%
sqlRst.next();
i++;
}
}
%>
</ul></td></table>
</body>
</html>
<%
//关闭结果集
sqlRst.close();
//关闭SQL语句对象
sqlStmt.close();
//关闭数据库
sqlCon.close();
%>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=726887