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

 详细的jsp分页

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


我的一个详细的jsp分页程序!(oracle+jsp+apache)
一 前提
希望最新的纪录在开头给你的表建立查询:
表:mytable
查询:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号

二 源程序
<%string sconn="你的连接"
class.forname("oracle.jdbc.driver.oracledriver");
connection conn=drivermanager.getconnection(sconn,"你的用户名","密码");
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
statement stmtcount=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);

resultset rs=stmt.executequery("select * from mytable_view");
string sqlcount="select count(*) from mytable_view";
resultset rscount=stmtcount.executequery(sqlcount);

int pagesize=你的每页显示纪录数;
int rowcount=0; //总的记录数
while (rscount
int pagecount; //总的页数
int currpage; //当前页数
string strpage;
strpage=request.getparameter("page");
if (strpage==null){
currpage=1;
}
else{
currpage=integer.parseint(strpage);
if (currpage<1) currpage=1;
}
pagecount=(rowcount+pagesize-1)/pagesize;
if (currpage>pagecount) currpage=pagecount;

int thepage=(currpage-1)*pagesize;
int n=0;
rs.absolute(thepage+1);
while (n<(pagesize)&&!rs
%>
<%rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%>

//下面是 第几页等
<form name="sinfo" method="post" action="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>" onsubmit="return testform(this)">
第<%=currpage%>页 共<%=pagecount%>页 共<%=rowcount%>条
<%if(currpage>1){%><a href="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>">首页</a><%}%>
<%if(currpage>1){%><a href="sbinfo_index.jsp?page=<%=currpage-1%>&condition=<%=condition%>&type=<%=type%>">上一页</a><%}%>
<%if(currpage<pagecount){%><a href="sbinfo_index.jsp?page=<%=currpage+1%>&condition=<%=condition%>&type=<%=type%>">下一页</a><%}%>
<%if(pagecount>1){%><a href="sbinfo_index.jsp?page=<%=pagecount%>&condition=<%=condition%>&type=<%=type%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">页
<input type="submit" name="submit" size="4" value="go" style="font-size:9px">
</form>

 本文Tags分页  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:使用JSP标记库校验用户输入
· 下一篇:如何捕获音频及输出音频
· JSP中的TagLib应用(4-2)
· 七、HTTP应答状态
· JDBCTM 指南:入门6-PreparedStatement
· JSP中的TagLib应用(4-4)
· Tomcat中文手册(1)


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