📄 steptwo.jsp
字号:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="db.ConnOracle"/>
<%!
ResultSet rs = null;
String sql = "";
int PageSize = 4;
int Page = 2;
String str = "";
public String ShowOnePage(ResultSet rs, int Page, int PageSize) {
str = "";
// 先将记录指针定位到相应的位置
try {
rs.absolute( (Page-1) * PageSize + 1);
}catch(SQLException e) {
}
for(int i=1; i<=PageSize; i++) {
str += RsToGbook(rs);
try {
if(!rs.next()) break;
}catch(Exception e) {
e.printStackTrace();
}
}
return str;
}
// 显示单行记录子模块
public String RsToGbook( ResultSet rs ) {
String text= "";
try {
text += "<tr>";
text += "<td>" + rs.getString("stockid") + "</td>";
text += "<td>" + rs.getString("stockname") + "</td>";
text += "<td>" + rs.getFloat("shoupan") + "</td>";
text += "<td>" + rs.getFloat("zhangdie") + "</td>";
text += "<td>" + rs.getFloat("stockmax") + "</td>";
text += "<td>" + rs.getFloat("stockmin") + "</td>";
text += "<td>" + rs.getFloat("stocknum") + "</td>";
text += "</tr>";
}catch(Exception e) {
e.printStackTrace();
}
return text;
}
%>
<%
sql = "select * from stock";
try {
rs = conn.query( sql );
}catch(Exception e) {
out.println("访问数据库出错!");
}
%>
<html>
<head>
<title>分页浏览</title>
</head>
<body bgcolor="#FFFFFF">
<h2 align="center">分页控制第二步</h2>
<hr>
<center>
<table border>
<tr bgcolor=lightblue>
<th>stockid</th>
<th>stockname</th>
<th>shoupan</th>
<th>zhangdie</th>
<th>stockmax</th>
<th>stockmin</th>
<th>stocknum</th>
</tr>
<%
try {
if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
Page = 1;
else
Page = Integer.parseInt(request.getParameter("Page"));
} catch(java.lang.NumberFormatException e) { // 捕获用户从浏览器地址拦直接输入Page=a所造成的异常
Page = 1;
}
out.println(ShowOnePage(rs, Page, PageSize));
%>
</table>
</center>
<hr>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -