<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*"%>
<%@ page import="myBean.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查询数据库</title>
</head>
<body>
<%
	String pg = request.getParameter("page");
	if(pg==null || pg=="") {
		out.print("参数有误");
		return;
	}
%>
<jsp:useBean id="db" scope="page" class="myBean.QueryPage" />
<p>数据库内容：
<table border="1" width="95%" align="center">
<tr>
	<td with="30%"><b>姓名</b></td>
	<td with="70%"><b>电子邮件</b></td>
</tr>
<%
	String sql= "select name, email from users";
	int i=0;
	int pgsize = 5;
	int curpage = Integer.parseInt(pg);
	int totalpage = db.totalPage(pgsize);
	
	try{
		ResultSet rs = db.getPageof(sql, pg, pgsize);
		if(rs != null) {
			while(rs.next() && i<pgsize) {
%>
<tr>
	<td>
	<%=rs.getString("name")%>
	</td>
	<td>
	<%=rs.getString("email")%>
	</td>
</tr>
<%
				i++;
			}
		}
	}catch(SQLException e) {}
%>
</table>
<a href="userinfo.jsp">返回</a>
共<%=totalpage%>页&nbsp;
<%
if(curpage>1 && totalpage>1)
	out.print("<a href=\"list_userinfo2.jsp?page="+ (curpage-1)+"\">上一页</a>");
else
	out.print("上一页");
%>&nbsp;
<%
if(curpage<totalpage)
	out.print("<a href=\"list_userinfo2.jsp?page="+ (curpage+1)+"\">下一页</a>");
else
	out.print("下一页");
%>
<form method="get" action="list_userinfo2.jsp">
跳到第<select name="page" OnChange="document.forms[0].submit()">
<script language="JavaScript">
	for(i=1; i<=<%=totalpage%>; i++)
		document.write("<option value="+i+">"+i+"</option>")
	document.forms[0].page.options[<%=curpage-1%>].selected = true;
</script>		
	</select>页
</form>
</body>

</html>