<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.sql.*, chap03.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登陆验证</title>
</head>
<body>
<%
String userName = (String)session.getAttribute("userName");
if(userName != null){
Integer I = (Integer)session.getAttribute("userGrade");
out.println("你好! " + userName + "<br>");
out.println("这个页面为限制页面,你是" + I + "级用户欢迎你进入!" + "<br>");
}
else
{
out.println("对不起,你还没有登录,请先<a href=index.html>登录</a>");
}
%>
现在时间是:<%=new java.util.Date() %>
<%
GetResult rp = new GetResult();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(rp.getOracle_url(), rp.getOracle_user(), rp.getOracle_pwd());
Statement stmtx = conn.createStatement();
String sqlRowNumber = "select count(*) as rowNumbers from user_list where user_password='121121'";
rs = stmtx.executeQuery(sqlRowNumber);
rs.next();
int rowNum = rs.getInt("rowNumbers");
stmtx.close();
rs.close();
int pageSize = 6;
int totalPage = 1;
int tmpPage = rowNum % pageSize;
if(tmpPage == 0){
totalPage = rowNum / pageSize;
}
else totalPage = rowNum / pageSize + 1;
if(totalPage == 0)
totalPage = 1;
int pagex = 1;
try{
if(request.getParameter("Page") == null ||request.getParameter("Page").equals("")){
pagex = 1;
}
else
pagex = Integer.parseInt(request.getParameter("Page"));
}catch(java.lang.NumberFormatException e){
pagex = 1;
}
if(pagex < 1)
pagex = 1;
if(pagex > totalPage)
pagex = totalPage;
out.println( "<br>" + pagex + "<br>");
int start = (pagex - 1) * pageSize;
int end = pagex * pageSize;
String sql = null;
if(pagex == 1)
sql = "select * from user_list where rownum <= ? and user_password='121121'";
else
sql = "select * from user_list where rownum <= ? and user_password='121121' minus select * from user_list where rownum <= ? and user_password='121121'";
stmt = conn.prepareStatement(sql);
if(pagex == 1){
stmt.setInt(1, end);
}
else{
stmt.setInt(1, end);
stmt.setInt(2, start);
}
rs = stmt.executeQuery();
// session.setAttribute("rowNumbers", N);
out.println("<BR>");
out.println("<table>");
out.println("<tr>");
out.println("<th>");
out.println("用户ID ");
out.println("</th>");
out.println("<th>");
out.println("用户名 ");
out.println("</th>");
out.println("<th>");
out.println("密 码 ");
out.println("</th>");
out.println("</tr>");
while(rs.next()){
out.println("<tr>");
out.println("<td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(2));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(3));
out.println("</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("<BR>");
if(pagex == 1)
out.println("上一页");
else if(pagex > 1)
out.println("<a href=HelloUser.jsp?Page="+(pagex-1)+">上一页</a>");
if(pagex == totalPage)
out.println("下一页");
else if(pagex < totalPage)
out.println("<a href=HelloUser.jsp?Page="+(pagex+1)+">下一页</a>");
out.println("<BR>");
}catch(SQLException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace();
}finally{
try{
if(stmt != null)
stmt.close();
if(conn != null){
conn.close();
}
if(rs != null)
rs.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
%>
</body>
</html>