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;
          ???????}



          }


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


          網站導航:
           
          主站蜘蛛池模板: 内乡县| 武平县| 黎川县| 昔阳县| 雷州市| 亚东县| 秦皇岛市| 襄城县| 洛南县| 北川| 收藏| 湟源县| 合作市| 兴山县| 惠安县| 龙泉市| 大姚县| 灵璧县| 连南| 江孜县| 彰武县| 玛曲县| 樟树市| 行唐县| 富锦市| 独山县| 高雄县| 界首市| 昌邑市| 册亨县| 东兴市| 勐海县| 富宁县| 广州市| 托里县| 惠水县| 丹江口市| 汝州市| 舟山市| 新晃| 聂荣县|