动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Jsp → 阅读文章

 jsp中实现分页

作者来源: 
阅读 2575 人次 , 2006-3-29 4:23:00 


page是关键字,不能当变量。

conn.jsp

<%
string sdbdriver = \"com.ibm.db2.jdbc.app.db2driver\";
string sconnstr = \"jdbc:db2:faq\";
connection conn = null;
statement stmt = null;
resultset rs=null;
try {
class.forname(sdbdriver);
}
catch(java.lang.classnotfoundexception e) {
out.print(\"faq(): \" + e.getmessage());
}

try{
conn = drivermanager.getconnection(sconnstr,\"wsdemo\",\"wsdemo1\");
stmt = conn.createstatement();
}catch(sqlexception e){
out.print(e.tostring());
}
%>

query.jsp

<%@ page language=\"java\" import=\"java.sql.*\" %>
<%@ page contenttype=\"text/html; charset=gb2312\" %>
<%@ include file=\"conn.jsp\" %>
<%
......
int pages=0;
int pagesize=10;
resultset result = null;
resultset rcount = null;

pages = new integer(request.getparameter(\"pages\")).intvalue();

if (pages>0)
{

string sql=\" state=\'我不傻\'\";
int count=0;
try {
rcount = stmt.executequery(\"select count(id) as id from user where \"+sql);
catch(sqlexception ex) {
out.print(\"aq.executequery: \" + ex.getmessage());
}
if(rcount.next())
count = rcount.getint(\"id\");
rcount.close();
if (count>0)
{
sql=\"select * from user where \"+sql;
try {
result = stmt.executequery(sql);
}
catch(sqlexception ex) {
out.print(\"aq.executequery: \" + ex.getmessage());
}
int i;
string name;
// result.first();
// result.absolute((pages-1)*pagesize);
// 此方法jdbc2.0支持。编译通过,但执行不过,不知是不是跟驱动有关,只好用下面的笨办法。
for(i=1;i<=(pages-1)*pagesize;i++)
result.next();
for(i=1;i<=pagesize;i++) {
if (result.next()) {
name=result.getstring(\"name\");
out.print(name);
}
result.close();
int n= (int)(count/pagesize);
if (n*pagesize<count) n++;
if (n>1)
{for(i=1;i<=n;i++)
out.print(\"<a href=query.jsp?pages=\"+i+\">\"+i+\" </a>\");

}

}

}

%>

 本文Tags分页  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:用jsp如何读取access数据库
· 下一篇:JSP生成jpeg图片用于投票
· 如何捕获音频及输出音频
· Resin在Windows系统下的安装
· JSP与JavaBean
· Servlet基本结构
· Java Web Server2.0 


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077