求大神,,jsp连接数据库并分页的代码(分页代码实在jsp中实现的)

天地人和 2024-05-28 12:24:23
最佳回答
<%@ page language="j**a" import="j**a.util.*,j**a.sql.resultset" contenttype="text/html; charset=utf-8"%><%@page import="com.dao.trainingdao"%><%@page import="com.db.dbutil"%><%string path = request.getcontextpath();string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";resultset rs = **;rs = dao.find();//根据后台的查询方法查询数据,你也可以在把你的查询方法放在jsp页面中,这个就要你自己写了,也就一个jdbc连接,然后查询数据库//设置每张网页显示三笔记录(每页显示的记录数)int pagesize=30;//设置欲显示的页数(初始页)int showpage=1;//resultset的记录笔数(总记录数)int rowcount=0;//resultset分页后的总数(总页数)int pagecount=0;try{//将指标移至最后一条记录rs.last();//获取记录总数rowcount=rs.getrow();}catch(exception ex){out.print("查询数据库连接失败,请稍后重试。");}//计算显示的页数(关键)pagecount=((rowcount%pagesize)==0?(rowcount/pagesize):(rowcount/pagesize)+1);string topage=request.getparameter("topage");//判断是否取得topage参数if(topage!=**){//取得指定显示的分页页数showpage=integer.parseint(topage);//下面的语句判断用户输入的页数是否正确if(showpage>=pagecount){showpage=pagecount;}else if(showpage<=0){showpage=1;}}%><!doctype html public "-//w3c//dtd html 4.01 transitional//en"><html><head><base href="<%=basepath%>"><title>培训查询</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="th** ** my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">.inp_text{width:120px; height:20px; border:1px solid #004000; line-height:20px;}/*所有链接样式*/a:link{font-size:14px;text-decoration:none; color:#333333;}a:v**ited{font-size:14px; text-decoration:none; color:#333333;}a:active{font-size:14px; text-decoration:none; color:#ff0000;}a:hover{font-size:14px; text-decoration:none; color:#ff0000;}body{font-size:12px; color:#000000;}</style></head><body><div align="center"><h3>培训信息查询</h3></div><table width="800" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#000000" style="font-size:12px; border-collapse:collapse;" ><tr><th width="40" height="30" align="center">姓名</th><th width="30" align="center">性别</th><th width="30" align="center">年龄</th><th width="65" align="center">职务</th></tr><%//计算欲显示页的第一笔记录位置rs.absolute((showpage-1)*pagesize+1);for(int i=1;i<=pagesize;i++){%><tr><td height="35" align="center"><%=rs.getstring("pname") %></td><td align="center"><%=rs.getstring("gender") %></td><td align="center"><%=rs.getstring("age") %></td><td align="left"><%=rs.getstring("post") %></td></tr><%if(!rs.next()){//跳出for循环break;}}dbutil.closeconnection();%></table><table width="540" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:22px;font-size:14px; color:#000000;"><tr><td valign="top">共有<%=rowcount %>条数据,当前在第<font style="font-size:14px;" color="red"><%=showpage %></font>页,共<%=pagecount %>页</td><td valign="top"><a href="loadall.jsp?topage=<%=1 %>">第一页</a><%//判断当前是否在第一页,不是第一页,则显示到第一页与下一页的连接if(showpage!=1){%><a href="loadall.jsp?topage=<%=showpage-1 %>">上一页</a><%}//判断是否在最后一页,是,则显示到最后一页和下一页if(showpage!=pagecount){%><a href="/training/loadall.jsp?topage=<%=showpage+1 %>">下一页</a><a href="/training/loadall.jsp?topage=<%=pagecount %>">最后一页</a><%}%></td><td valign="top"><form action="loadall.jsp" method="post" name="form1"><input type="text" name="topage" value="<%=showpage %>" onkeyup="th**.value=th**.value.replace(/\d/g,'')"onafterpaste="th**.value=th**.value.replace(/\d/g,'')" style="height:20px;width:30px">页<a href="j**ascript:window.document.form1.submit();" style=" font-weight:bold;">go</a></form></td></tr></table></body></html> 20210311
汇率兑换计算器

类似问答
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。