<%
//变量声明
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();
%>
新闻热点
疑难解答