佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > jsp頁面數據分頁模仿百度分頁效果(實例講解)

jsp頁面數據分頁模仿百度分頁效果(實例講解)

熱門標簽:銀行業(yè)務 服務器配置 阿里云 團購網站 科大訊飛語音識別系統(tǒng) Mysql連接數設置 電子圍欄 Linux服務器

廢話不多說,直接上代碼

請根據自己的項目、包名修改

%@page import="web09.shop.DBUtil"%>
%@page import="java.sql.ResultSet"%>
%@page import="java.sql.PreparedStatement"%>
%@page import="java.sql.Connection"%>
%@ page language="java" pageEncoding="UTF-8"%>
!DOCTYPE html>
html>
head>
  meta charset="UTF-8">
  title>數據分頁/title>
  style type="text/css">
    .page a{
      min-width: 34px;
      height: 34px;
      border: 1px solid #e1e2e3;
      cursor: pointer;
      display:block;
      float: left;
      text-decoration: none;
      text-align:center;
      line-height: 34px;      
    }
    
    .page a:HOVER {
      background: #f2f8ff;
      border: 1px solid #38f ;
    }
    .page a.prev{
      width:50px;
    }
    .page span{
      width: 34px;
      height: 34px;
      border: 1px solid transparent;
      cursor: pointer;
      display:block;
      float: left;
      text-decoration: none;
      text-align:center;
      line-height: 34px;
      cursor: default;
    }
  /style>
/head>

body>
table class="tt" border="1" align="center" width="80%" cellpadding="10">
  tr>
    th>ID/th>
    th>姓名/th>
    th>年齡/th>
    th>專業(yè)/th>
  /tr>
  %
  DBUtil dbutil=new DBUtil();
  Connection conn=dbutil.getCon();
  //Connection conn = new DBUtil().getCon();
  PreparedStatement pstmt1 = conn.prepareStatement("select count(*) from student");
  ResultSet rs1 = pstmt1.executeQuery();
  rs1.next();
  int recordCount = rs1.getInt(1);   //記錄總數
  int pageSize = 10;          //每頁記錄數
  int start=1;            //顯示開始頁
  int end=10;              //顯示結束頁
  int pageCount = recordCount%pageSize==0 ? recordCount/pageSize : recordCount/pageSize+1; 
  int currPage = request.getParameter("p")==null ? 1 : Integer.parseInt(request.getParameter("p"));
  
  currPage = currPage1 ? 1 : currPage;
  currPage = currPage>pageCount ? pageCount : currPage;
  
  PreparedStatement pst = conn.prepareStatement("select * from student limit ?,?");
  pst.setInt(1,currPage*pageSize-pageSize);
  pst.setInt(2,pageSize);
  ResultSet rs = pst.executeQuery();
  
  while(rs.next()){
  %>
  tr align="center">
  td>%=rs.getInt(1) %>/td>
  td>%=rs.getString(2) %>/td>
  td>%=rs.getInt("age") %>/td>
  td>%=rs.getString(4) %>/td>
  /tr>
  %
  }
  %>
  tr>
     th colspan="4" class="page">
       % 
         out.print(String.format("a class=\"prev\" href=\"?p=%d\">首頁/a>",1));
         if(currPage>=7){
           start=currPage-5;
           end=currPage+4;
         }
         if(start>(pageCount-10)){
           start=pageCount-9;
         }
         if(currPage>1){
           out.print(String.format("a class=\"prev\" href=\"?p=%d\">上一頁/a>",currPage-1));
         }
         
         for(int i=start;i=end;i++){
           if(i>pageCount) break;
           String pageinfo=String.format("a href=\"?p=%d\">%d/a>",i,i);
           if(i==currPage){
             pageinfo=String.format("span>%d/span>",i);
           }
           out.print(pageinfo);
         }
         
         if(currPage=pageCount){
           out.print(String.format("a class=\"prev\" href=\"?p=%d\">下一頁/a>",currPage+1));
         }
         
         out.print(String.format("a class=\"prev\" href=\"?p=%d\">尾頁/a>",pageCount)); 
       %>
     /th>
   /tr>
/table>
/body>
/html>

以上這篇jsp頁面數據分頁模仿百度分頁效果(實例講解)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • nodejs個人博客開發(fā)第六步 數據分頁
  • JSP數據分頁導出下載顯示進度條樣式
  • JS代碼實現table數據分頁效果
  • jsp+servlet+javabean實現數據分頁方法完整實例
  • 無JS,完全php面向過程數據分頁實現代碼
  • JSP數據庫操數據分頁顯示
  • jquery+json實現數據列表分頁示例代碼
  • js前臺分頁顯示后端JAVA數據響應
  • JS實現table表格數據排序功能(可支持動態(tài)數據+分頁效果)
  • js對象實現數據分頁效果

標簽:棗莊 大理 蚌埠 萍鄉(xiāng) 江蘇 衡水 衢州 廣元

巨人網絡通訊聲明:本文標題《jsp頁面數據分頁模仿百度分頁效果(實例講解)》,本文關鍵詞  ;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    盐池县| 聂荣县| 廊坊市| 罗源县| 成武县| 赤峰市| 昭苏县| 谢通门县| 忻城县| 星座| 武陟县| 航空| 界首市| 石门县| 花莲县| 抚州市| 广饶县| 阳江市| 建水县| 秦安县| 交城县| 思南县| 北碚区| 白城市| 关岭| 泾阳县| 泰宁县| 新和县| 望谟县| 彭州市| 杨浦区| 三河市| 资源县| 阳高县| 留坝县| 东台市| 双江| 宁安市| 曲沃县| 浙江省| 淅川县|