jsp分頁顯示

來源:互聯網
上載者:User

jsp分頁顯示

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>

<script language="javascript">
function newwin(url) {
var

newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,

menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
<script LANGUAGE="javascript">
function submit10()
{
self.location.replace("fenye1.jsp")
}
</script>
<%//變數聲明
java.sql.Connection sqlCon; //資料庫連接對象
java.sql.Statement sqlStmt; //SQL語句對象
java.sql.ResultSet sqlRst; //結果集對象
java.lang.String strCon; //資料庫連接字串
java.lang.String strSQL; //SQL語句
int intPageSize; //一頁顯示的記錄數
int intRowCount; //記錄總數
int intPageCount; //總頁數
int intPage; //待顯示頁碼
java.lang.String strPage;
int i;
//設定一頁顯示的記錄數
intPageSize = 4;
//取得待顯示頁碼
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中沒有page這一個參數,此時顯示第一頁資料
intPage = 1;
}
else{//將字串轉換成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
//裝載JDBC驅動程式
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//設定資料庫連接字串
strCon = "jdbc:odbc:heyang";
//串連資料庫
sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","");
//建立一個可以滾動的唯讀SQL語句對象
sqlStmt =

sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.Result

Set.CONCUR_READ_ONLY);//準備SQL語句
strSQL = "select user_id,user_name from userinfo order by user_id desc";
//執行SQL語句並擷取結果集
sqlRst = sqlStmt.executeQuery(strSQL);
//擷取記錄總數
sqlRst.last();//??游標在最後一行
intRowCount = sqlRst.getRow();//獲得當前行號
//記算總頁數
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//調整待顯示的頁碼
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>會員管理</title>
</head>
<body>
<form method="POST" action="fenye1.jsp">
第<%=intPage%>頁 共<%=intPageCount%>頁

<%if(intPage<intPageCount){%><a

href="fenye1.jsp?page=<%=intPage+1%>">下一頁

</a><%}%> <%if(intPage>1){%><a href="fenye1.jsp?page=<%=intPage-1%>">

上一頁</a><%}%>
轉到第:<input type="text" name="page" size="8"> 頁
<span><input class=buttonface type=´submit´ value=´GO´ name=´cndok´></span>
</form>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<th>ID</th>
<th>使用者名稱</th>
<th width=´8%´>刪除</th>
</tr>
<%
if(intPageCount>0){
//將記錄指標定位到待顯示頁的第一條記錄上
sqlRst.absolute((intPage-1) * intPageSize + 1);
//顯示資料
i = 0;
String user_id,user_name;
while(i<intPageSize && !sqlRst.isAfterLast()){
user_id=sqlRst.getString(1);
user_name=sqlRst.getString(2);
%>
<tr>
<td><%=user_id%></td>
<td><%=user_name%></td>
<td width=´8%´ align=´center´><a href="delete.jsp?user_id=<%=user_id%>"

onClick="return newwin(this.href);">刪除</a></td>
</tr>
<%
sqlRst.next();
i++;
}
}
%>
</table>

</body>
</html>
<%
//關閉結果集
sqlRst.close();
//關閉SQL語句對象
sqlStmt.close();
//關閉資料庫
sqlCon.close();
%>

 

 

相關文章

聯繫我們

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