点击这里给我发消息 点击这里给我发消息

效率比较高的jsp分页程序

添加时间:2013-12-7
    相关阅读: 数据库 程序 Access

    可通过下拉框跳转到指定页

    <script language="javascript">
     function gopage()
     {
      document.listpage.submit();
     }
     function previouspage()
     {
      if ( (parseInt(document.listpage.page.value) ) < 1)
        document.listpage.page.value = 1;
      else
      {
        document.listpage.page.value = parseInt(document.listpage.page.value) - 1;
        document.listpage.submit();
      }
     }
     function nextpage()
     {
      document.listpage.page.value = parseInt(document.listpage.page.value) + 1;
         document.listpage.submit();
     }
     function gopagebyno(pageno)
     {
      document.listpage.page.value = pageno;
      document.listpage.submit();
     }


    </script>
    <%
    Connection m_Connection=null;
    Statement m_Statement=null;
    ResultSet m_ResultSet=null;
    String sql;
    String dbpath = application.getRealPath("/数据库位置"); //将相对路径转化成物理路径
    String connStr ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    m_Connection=DriverManager.getConnection(connStr);
    m_Statement=m_Connection.createStatement(1004,1007);
    sql=查询语句;
    m_ResultSet=m_Statement.executeQuery(sql);
    %>
     <div>
       <table class="list" width="580" >
         <%
     int i=1;
     int rscount=0;//记录条数
     int allpages=1;//所有页数
     if(m_ResultSet!=null)
       {m_ResultSet.last();
               rscount=m_ResultSet.getRow();
        if(rscount>0)
            {allpages=rscount / 10;
              if(rscount>(allpages * 10)){allpages=allpages+1;}
               if(curpage==1){m_ResultSet.first();}
                      else{m_ResultSet.absolute(10*(curpage-1)+1);}
               while(!m_ResultSet.isAfterLast())
                       {%>
         <tr valign="top" height="15">
                         <td><%=m_ResultSet.getString("d_d_name")%></td>
           <td><%=m_ResultSet.getString("d_t_name")%></td>
           <td><input  style="margin:0px;" type="button" name="Submit2" onClick="actiondo('del','<%=m_ResultSet.getString("d_d_id")%>','<%=curpage%>')" value="删除"><input  style="margin:0px;"  type="button" name="Submit3" onClick="actiondo('edit','<%=m_ResultSet.getString("d_d_id")%>','<%=curpage%>')" value="编辑"></td>
                       </tr>
         <%
                        i++;
                        if(i>10){break;}
         m_ResultSet.next();
                       }
      }
                  m_ResultSet.close();
       }
           %>
    </table>
    </div>
    <div align="center">
        <form name="listpage">
     <font color='#000080'>&nbsp;页次:</font>
     <b><font color=red><%=curpage%></font></b><font color='#000080'>/<b><%=allpages%></b>&nbsp;</font>
     <font color='#000080'>
     <% if (curpage!=1)
       {out.print("<a href='javascript:gopagebyno(1)'>首页</a>");}
      else
      {out.print("首页");}
      %>
     </font>
     <font color='#000080'>
     <%if(curpage!=1)
          {out.print("<a href='javascript:previouspage()'>上页</a>");}
         else
       {out.print("上页");}
      %>
      </font>
     <font color='#000080'>
     <% if(allpages!=0&&(curpage<allpages))
         {out.print("<a href='javascript:nextpage()'>下页</a>");}
         else
        {out.print("下页");}
     %>
             </font>
     <font color='#000080'>
     <% if(allpages!=0&&(curpage<allpages))
         {out.print("<a href='javascript:gopagebyno("+allpages+")'>尾页</a>");}
        else
        {out.print("尾页");}
     %>
            </font>
     <select name="page" onChange="javascript:gopagebyno(document.listpage.page.value)" >
     <%for(i=1;i<=allpages;i++)
         {if(curpage==i){out.print("<option value='"+i+"' selected='selected'>"+i+"</option>");}
      else{out.print("<option value='"+i+"'>"+i+"</option>");}
         }
     %>
     </select>
       </form>
    </div>

 

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册