熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

效率比較高的jsp分頁程序

2022-06-13   來源: Java核心技術 

  可通過下拉框跳轉到指定頁

  <script language=javascript>
     function gopage()
     {
      documentlistpagesubmit();
     }
     function previouspage()
     {
      if ( (parseInt(documentlistpagepagevalue) ) < )
        documentlistpagepagevalue = ;
      else
      {
        documentlistpagepagevalue = parseInt(documentlistpagepagevalue) ;
        documentlistpagesubmit();
      }
     }
     function nextpage()
     {
      documentlistpagepagevalue = parseInt(documentlistpagepagevalue) + ;
         documentlistpagesubmit();
     }
     function gopagebyno(pageno)
     {
      documentlistpagepagevalue = pageno;
      documentlistpagesubmit();
     }

  </script>
    <%
    Connection m_Connection=null;
    Statement m_Statement=null;
    ResultSet m_ResultSet=null;
    String sql;
    String dbpath = applicationgetRealPath(/數據庫位置); //將相對路徑轉化成物理路徑
    String connStr =jdbc:odbc:Driver={Microsoft Access Driver (*mdb)};DBQ=+dbpath;
    ClassforName(sunjdbcodbcJdbcOdbcDriver);
    m_Connection=DriverManagergetConnection(connStr);
    m_Statement=m_ConnectioncreateStatement();
    sql=查詢語句;
    m_ResultSet=m_StatementexecuteQuery(sql);
    %>
     <div>
       <table class=list width= >
         <%
     int i=;
     int rscount=;//記錄條數
     int allpages=;//所有頁數
     if(m_ResultSet!=null)
       {m_ResultSetlast();
               rscount=m_ResultSetgetRow();
        if(rscount>)
            {allpages=rscount / ;
              if(rscount>(allpages * )){allpages=allpages+;}
               if(curpage==){m_ResultSetfirst();}
                      else{m_ResultSetabsolute(*(curpage)+);}
               while(!m_ResultSetisAfterLast())
                       {%>
         <tr valign=top height=>
                         <td><%=m_ResultSetgetString(d_d_name)%></td>
           <td><%=m_ResultSetgetString(d_t_name)%></td>
           <td><input  type=button name=Submit onClick=actiondo(del<%=m_ResultSetgetString(d_d_id)%><%=curpage%>) value=刪除><input    type=button name=Submit onClick=actiondo(edit<%=m_ResultSetgetString(d_d_id)%><%=curpage%>) value=編輯></td>
                       </tr>
         <%
                        i++;
                        if(i>){break;}
         m_ResultSetnext();
                       }
      }
                  m_ResultSetclose();
       }
           %>
    </table>
    </div>
    <div align=center>
        <form name=listpage>
     <font color=#>&nbsp;頁次:</font>
     <b><font color=red><%=curpage%></font></b><font color=#>/<b><%=allpages%></b>&nbsp;</font>
     <font color=#>
     <% if (curpage!=)
       {outprint(<a javascript:gopagebyno()>首頁</a>);}
      else
      {outprint(首頁);}
      %>
     </font>
     <font color=#>
     <%if(curpage!=)
          {outprint(<a javascript:previouspage()>上頁</a>);}
         else
       {outprint(上頁);}
      %>
      </font>
     <font color=#>
     <% if(allpages!=&&(curpage<allpages))
         {outprint(<a javascript:nextpage()>下頁</a>);}
         else
        {outprint(下頁);}
     %>
             </font>
     <font color=#>
     <% if(allpages!=&&(curpage<allpages))
         {outprint(<a javascript:gopagebyno(+allpages+)>尾頁</a>);}
        else
        {outprint(尾頁);}
     %>
            </font>
     <select name=page onChange=javascript:gopagebyno(documentlistpagepagevalue) >
     <%for(i=;i<=allpages;i++)
         {if(curpage==i){outprint(<option value=+i+ selected=selected>+i+</option>);}
      else{outprint(<option value=+i+>+i+</option>);}
         }
     %>
     </select>
       </form>
    </div>


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26911.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.