hays

          海納百川
          posts - 25, comments - 48, trackbacks - 0, articles - 0
            BlogJava :: 首頁 ::  :: 聯系 :: 聚合  :: 管理

          頁面分頁函數

          Posted on 2006-10-30 15:49 hays(海納百川) 閱讀(238) 評論(0)  編輯  收藏

          ?

          package ?com.vitamin.download;
          import ?javax.servlet. * ;
          import ?javax.servlet.http. * ;
          import ?java.math. * ;
          import ?java.sql. * ;

          public ? class ?Pagination?
          {
          ????
          ????
          private ?String?strPage? = ? null ;
          ????
          private ? int ?curPage; // 當前頁;
          ???? private ? int ?m_rows; // 每頁包括的幾個數據項;
          ???? private ? int ?totalPage; // 總頁數
          ????
          ????
          public ?Pagination()
          ????
          {
          ????????
          ????}

          ????
          ????
          public ? int ?getRows()
          ????
          {
          ????????
          return ? this .m_rows;
          ????}

          ????
          ????
          public ?Pagination( int ?rows)
          ????
          {
          ????????
          this .setRows(rows);
          ????}

          ????
          ????
          public ?String?getstrPage(HttpServletRequest?request,String?page)
          ????
          {
          ????????
          try
          ????????
          {
          ????????????????strPage?
          = ?request.getParameter(page);
          ????????}

          ????????
          catch (Exception?e)
          ????????
          {
          ????????????????System.out.print(e.getMessage());
          ????????}

          ????????
          return ?strPage;
          ????}

          ????
          ????
          public ? int ?getcurPage(String?strPage)
          ????
          {
          ????????
          try
          ????????
          {
          ????????????
          if (strPage == null )
          ????????????
          {
          ????????????????
          this .curPage? = 1 ;
          ????????????}

          ????????????
          else
          ????????????
          {
          ????????????????
          this .curPage? = ?Integer.parseInt(strPage);
          ????????????????
          if ( this .curPage < 1 )
          ????????????????
          {
          ????????????????????
          this .curPage? = 1 ;
          ????????????????}

          ????????????}

          ????????????
          ????????}

          ????????
          catch (Exception?e)
          ????????
          {
          ????????????System.out.print(
          " curPages " );
          ????????}

          ????????
          return ? this .curPage;
          ????}

          ????
          ?????
          public ? void ?setRows( int ?rows)
          ?????
          {
          ???????????m_rows
          = rows;
          ?????}

          ???????
          // ?取得頁數
          ??????
          ?????
          public ? int ?getTotalPages( int ?rowcounts)
          ?????
          {
          ???????????
          int ?test; // ?變量
          ???????????test = rowcounts % m_rows; // ?取得余數
          ??????????? if (test == 0 )
          ???????????
          {
          ???????????????totalPage?
          = ?rowcounts / m_rows; // ?可以整除,總頁數;
          ???????????}

          ???????????
          else
          ???????????
          {
          ???????????????totalPage
          = rowcounts / m_rows + 1 ; // ?不是的話就加一??
          ???????????}

          ???????????
          return ?totalPage; // ?返回頁數
          ??????}

          ???????
          // ?結果集的返回
          ???????
          ?????
          public ?ResultSet?getPageSet(ResultSet?rs, int ?curPages)
          ?????
          {
          ???????????
          if (curPages == 1 )
          ???????????
          {
          ??????????????
          ???????????????
          return ?rs; // ?如果就只有一頁
          ???????????}

          ???????????
          else
          ???????????
          {
          ???????????????
          int ?i = 1 ;
          ???????????????
          try
          ???????????????
          {
          ???????????????????
          while (rs.next()) // 使rs跳到(curPages-1)*m_rows?那行;
          ??????????????????? {
          ???????????????????????i
          = i + 1 ;
          ???????????????????????
          if (i > ((curPages - 1 ) * m_rows))
          ???????????????????????
          {
          ???????????????????????????
          break ; // ?退出
          ???????????????????????}

          ???????????????????}

          ???????????????????
          return ?rs; // ?從退出開始將結果集返回
          ???????????????}

          ???????????????
          catch (Exception?e)
          ???????????????
          {
          ???????????????????System.out.print(e.getMessage());
          ???????????????}

          ???????????}

          ???????????
          return ?rs;
          ???????}



          }


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 姚安县| 紫金县| 湟源县| 丰镇市| 纳雍县| 长沙市| 清原| 申扎县| 台东县| 达拉特旗| 夏河县| 布拖县| 托里县| 花垣县| 金门县| 安庆市| 鸡东县| 巴林右旗| 云林县| 华阴市| 东海县| 石家庄市| 澄迈县| 平阴县| 时尚| 资兴市| 沁水县| 桂阳县| 吉木乃县| 柳江县| 巴青县| 漠河县| 东平县| 蓬溪县| 印江| 铁岭县| 忻州市| 上饶县| 修水县| 永顺县| 古丈县|