詳細的jsp分頁

來源:互聯網
上載者:User
js|分頁


我的一個詳細的jsp分頁程式!(oracle+jsp+apache)
一 前提
希望最新的紀錄在開頭給你的表建立查詢:
表:mytable
查詢:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序號create sequence mytable_sequence 來自動增加你的紀錄id號

二 來源程式
<%String sConn="你的串連"
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(sConn,"你的使用者名稱","密碼");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmtcount=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

ResultSet rs=stmt.executeQuery("select * from mytable_view");
String sqlcount="select count(*) from mytable_view";
ResultSet rscount=stmtcount.executeQuery(sqlcount);

int pageSize=你的每頁顯示紀錄數;
int rowCount=0; //總的記錄數
while (rscount
int pageCount; //總的頁數
int currPage; //當前頁數
String strPage;
strPage=request.getParameter("page");
if (strPage==null){
currPage=1;
}
else{
currPage=Integer.parseInt(strPage);
if (currPage<1) currPage=1;
}
pageCount=(rowCount+pageSize-1)/pageSize;
if (currPage>pageCount) currPage=pageCount;

int thepage=(currPage-1)*pageSize;
int n=0;
rs.absolute(thepage+1);
while (n<(pageSize)&&!rs
%>
<%rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%>

//下面是 第幾頁等
<form name="sinfo" method="post" action="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>" onSubmit="return testform(this)">
第<%=currPage%>頁 共<%=pageCount%>頁 共<%=rowCount%>條
<%if(currPage>1){%><a href="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>">首頁</a><%}%>
<%if(currPage>1){%><a href="sbinfo_index.jsp?page=<%=currPage-1%>&condition=<%=condition%>&type=<%=type%>">上一頁</a><%}%>
<%if(currPage<pageCount){%><a href="sbinfo_index.jsp?page=<%=currPage+1%>&condition=<%=condition%>&type=<%=type%>">下一頁</a><%}%>
<%if(pageCount>1){%><a href="sbinfo_index.jsp?page=<%=pageCount%>&condition=<%=condition%>&type=<%=type%>">尾頁</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">頁
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.