效率比較高的jsp分頁程式

來源:互聯網
上載者:User

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

<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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.