?? jsphelloworld.jsp
字號:
<%@page import="java.net.URL"%>
<%@page import="java.sql.*"%>
<%@page language="java"%>
<%@page contentType="text/html; charset=GBK"%><style type="text/css">
<!--
body {
background-color: #264989;
margin-left: 20px;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 20px;
}
body,td,th {
font-size: 12px;
}
.style1 {color: #FFFFFF}
-->
</style>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:oa";
int intPageSize; //一頁顯示的記錄數(shù)
int intRowCount; //記錄總數(shù)
int intPageCount; //總頁數(shù)
int intPage; //待顯示頁碼
java.lang.String strPage;
int i;
//設(shè)置一頁顯示的記錄數(shù)
intPageSize = 15;
//取得待顯示頁碼
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中沒有page這一個參數(shù),此時顯示第一頁數(shù)據(jù)
intPage = 1;
}
else{//將字符串轉(zhuǎn)換成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
Connection con= DriverManager.getConnection(url,"sa","12127922");
//創(chuàng)建statement對象
Statement stmt = con.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String sql="select id,user_name,user_id,sex from users order by id";
ResultSet rs=stmt.executeQuery(sql);
rs.last();
intRowCount = rs.getRow();
rs.first();
//記算總頁數(shù)
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//調(diào)整待顯示的頁碼
if(intPage>intPageCount)
{intPage = intPageCount;}
%>
<table width="300" border="0" cellspacing="0" bgcolor="#000033">
<tr bgcolor="#663300">
<td width="11%" height="25"><span class="style1 style1">ID</span></td>
<td width="27%" height="25"><span class="style1">用戶名</span></td>
<td width="20%" height="25"><span class="style1">用戶ID</span></td>
<td width="42%" height="25"><span class="style1">性別</span></td>
</tr>
<%
if(intPageCount>0){
//將記錄指針定位到待顯示頁的第一條記錄上
rs.absolute((intPage-1) * intPageSize + 1);
//顯示數(shù)據(jù)
i = 0;
while(i<intPageSize&&!rs.isAfterLast()){
%>
<tr bgcolor="#FFFFFF">
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
</tr>
<%
i++;
rs.next();
}
}
rs.close();
stmt.close();
%>
<tr bgcolor="#FFFFFF">
<td colspan="4">第<%=intPage%>頁 共<%=intPageCount%>頁 <%if(intPage<intPageCount){%><a href="JspHelloWorld.jsp?page=<%=intPage+1%>">下一頁</a><%}%> <%if(intPage>1){%><a href="JspHelloWorld.jsp?page=<%=intPage-1%>">上一頁</a><%}%> </td>
</tr>
</table>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -