JSP的分页技术及其应用.pptxVIP

  • 3
  • 0
  • 约4.03千字
  • 约 15页
  • 2019-12-23 发布于湖北
  • 举报
JSP程序设计;;;学习任务;任务六 JSP+JDBC详解;在实际应用中,如果从数据库中查询得到的记录特别多,甚至超过了显示器屏幕范围,这时可将结果分页显示。本例使用的数据库以及表是上一节使用的student数据库和info表。 假设总记录数为intRowCount,每页显示记录的数量为intPageSize,总页数为intPageCount,那么总页数的计算公式为: 如果(intRowCount % intPageSize)0,则intPageCount= intRowCount / intPageSize+1。 如果(intRowCount % intPageSize)=0,则intPageCount= intRowCount / intPageSize。 翻页后显示第intPage页的内容,将记录指针移动到(int1)*intPageSize+1。;;【例6-11】分页显示实例(pageBreak.jsp) %@page import=java.sql.*% %@page contentType=text/html pageEncoding=UTF-8% html head meta http-equiv=Content-Type content=text/html; charset=UTF-8 title分页浏览记录/title /head body center 分页显示记录内容 hr table border=1 bgcolor=cccfff align=center tr th学号/th th姓名/th th性别/th th年龄/th th体重/th /tr; % Class.forName( com.microsoft.sqlserver.jdbc.SQLServerDriver); String url=jdbc:sqlserver://localhost:1433;databasename= student; String user=sa; String password=root; Connection conn= DriverManager.getConnection(url,user,password); int intPageSize; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount; //总页数 int intPage; //待显示页码 String strPage; int i; intPageSize =2; //设置一页显示的记录数 strPage = request.getParameter(page); //取得待显示页码; if(strPage==null){ /*表明在QueryString中没有page这一个参数,此时显示第一页数据*/ intPage = 1; } else{ //将字符串转换成整型 intPage = java.lang.Integer.parseInt(strPage); if(intPage1) intPage=1; } Statement st

文档评论(0)

1亿VIP精品文档

相关文档