核心代码:
<%@ page contenttype="text/html" pageencoding="gb2312" language="java"%> <%@ page import="java.sql.*"%> <html> <head> <title>hello</title> </head> <body> <table border="1" spacing="2"> <%! public static final string driver = "com.mysql.jdbc.driver"; public static final string user = "root"; public static final string pass = ""; public static final string url = "jdbc:mysql://localhost:3306/teachinfo"; public static final int pagesize = 5; int pagecount; int curpage = 1; %> <% //一页放5个 string user = null; string pass = null; try{ class.forname(driver); connection con = drivermanager.getconnection(url,user,pass); string sql = "select * from department"; preparedstatement stat = con.preparestatement(sql,resultset.type_forward_only,resultset.concur_read_only); resultset rs = stat.executequery(); rs.last(); int size = rs.getrow(); pagecount = (size%pagesize==0)?(size/pagesize):(size/pagesize+1); string tmp = request.getparameter("curpage"); if(tmp==null){ tmp="1"; } curpage = integer.parseint(tmp); if(curpage>=pagecount) curpage = pagecount; boolean flag = rs.absolute((curpage-1)*pagesize+1); out.println(curpage);//输出到屏幕上 int count = 0; do{ if(count>=pagesize)break; int departmentid = rs.getint(1); string departmentname = rs.getstring(2); count++; %> <tr> <td><%=departmentid%></td> <td><%=departmentname%></td> </tr> <% }while(rs.next()); con.close(); } catch(exception e){ } %> </table> <a href = "fenye.jsp?curpage=1" >首页</a> <a href = "fenye.jsp?curpage=<%=curpage-1%>" >上一页</a> <a href = "fenye.jsp?curpage=<%=curpage+1%>" >下一页</a> <a href = "fenye.jsp?curpage=<%=pagecount%>" >尾页</a> 第<%=curpage%>页/共<%=pagecount%>页 </body> </html>
本篇代码希望各位朋友喜欢!
如对本文有疑问, 点击进行留言回复!!
unity的错误解决办法:NullReferenceException: Object reference not set to an instance of an object;tiny proje
Hadoop 之 HDFS (HDFS 数据流的 读写 流程)
听说你一读Spring源码就懵逼?我帮你把架子搭好了,你填就行!
首席架构师推荐:金融保险领域数字化转型实践--如何优雅地修改业务中台中分层应用Maven多模块的版本号?(命令导入式)
[JVM学习之路]一、初识JVM,了解其结构、模型及生命周期
网友评论