测试文件:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page pageEncoding="GB2312"%>
<%@ page language="java" %>
<%@ page import="java.util.Collection,java.util.Iterator"%>
<%@ page import="test.JavaBean.DB_Conn"%>
<%@ page import="test.JavaBean.DB_User"%>
<%@ page import="test.JavaBean.User"%>
<table align=center border=0 width=100% cellspacing=1 cellpadding=1>
<tr>
<td width=100% colspan=5 bgcolor=#3399ff>
<center><font color=#ffffff>成员列表</font></center>
</td>
</tr>
<tr>
<td width=10% bgcolor=#fcfcfc>用户名</td>
<td width=10% bgcolor=#fcfcfc>登录密码</td>
<td width=15% bgcolor=#fcfcfc>邮件地址</td>
</tr>
<%
if (request.getAttribute("c") == null) {
%>
<tr>
<td width= 75% colspan=5 bgcolor=#fcfcfc align=center>没有用户数据!</td>
</tr>
<% } else {
Collection c = (Collection) request.getAttribute("c");
if (c == null) {
%>
<tr>
<td width=100% colspan=5 bgcolor=#fcfcfc align=center>没有用户数据!</td>
</tr>
<%} else {
int totalPageNum = ((Integer) (request.getAttribute("totalPageNum"))).intValue();
int currentPage = 1;
if (request.getParameter("page") != null) {
currentPage = Integer.parseInt(request.getParameter("page"));
}
//输出用户数据
Iterator iterator = c.iterator();
while (iterator.hasNext()) {
User user = (User) iterator.next();
%>
<tr>
<td width=10% bgcolor=#fcfcfc><%=user.getUsername()%></a></td>
<td width=15% bgcolor=#fcfcfc><%=user.getPassword()%></td>
<td width=15% bgcolor=#fcfcfc><%=user.getEmail()%></td>
</tr>
<%}%>
<form name="list" method="GET">
<tr>
<td width=100% colspan=5 align=right bgcolor=#efefef>
<%for (int i = 1; i <= totalPageNum; i++) {%>
<a href="UserListServlet?page=<%=i %>">[<%=i%>]</a>
<% } %>共[<%=request.getAttribute("totalPageNum") %>]页
<input type="text" size="2" name="page" value="">
<input type="submit" name="go" value="Go">
</td>
</tr>
</form>
<%}
}
%>
<tr>
<td colspan=2 align=right> </td>
</tr>
</table>