
index.jsp:

<%@ page language="java"
import="java.util.*" pageEncoding="gbk"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<meta http-equiv="refresh" content="0;URL=peopleAction.do">

</head>

<body>

</body>

</html>

===============================================

pagenation.jsp

<%@ page contentType="text/html; charset=gbk" %>

<%@page
import="java.sql.*"%>

<%@page
import="java.util.*"%>

<%@page
import="com.domain.PeopleForm"%>

<html>

<meta http-equiv="Content-Type" content="text/html;charset=gbk">

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>

<link href="css/style.css" rel="stylesheet" type="text/css">

<%

List list = (List)request.getAttribute("list");
//
获取保存在request范围内的数据
int number = Integer.parseInt((String)request.getAttribute("number"));
int maxPage = Integer.parseInt((String)request.getAttribute("maxPage"));
int pageNumber = Integer.parseInt((String)request.getAttribute("pageNumber"));
int start = number*4;
//
开始条数
int over = (number+1)*4;
//
结束条数
int count=pageNumber-over;
//
还剩多少条记录
if(count<=0)
{
over=pageNumber;
}

%>

<head>

<title>利用查询结果集进行分页</title>

</head>

<body >

<table width="756" height="650" border="0" align="center" cellpadding="0"

cellspacing="0" >

<tr>

<td height="280">

<table width="635" border="1" align="center">

<tr align="center" bgcolor="#FFFFFF">

<td width="112" height="17"><span
class="style4">编号</span></td>

<td width="112"><span
class="style4">姓名</span></td>

<td width="112"><span
class="style4">性别</span></td>

<td width="112"><span
class="style4">年龄</span></td>

<td width="142"><span
class="style4">职位</span></td>

</tr>

<logic:iterate id="element" indexId="index" name="list"

offset="<%=String.valueOf(start)%>"

length="4"> <!-- 通过迭代标签将员工信息输出 -->

<tr align="center" bgcolor="#FFFFFF">

<td height="22">

<bean:write name="element" property="id"/>

</td>

<td>

<bean:write name="element" property="name"/>

</td>

<td><bean:write name="element" property="sex"/>

</td>

<td><bean:write name="element" property="age"/>岁</td>

<td><bean:write name="element" property="job"/>

</td>

</tr>

</logic:iterate>

</table>

</td>

</tr>

<tr>

<td valign="top">

<form name="form" method="post" action="peopleAction.do">

<table width="400" height="20" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td width="400" valign="middle" bgcolor="#CCCCCC">

共为<bean:write name="maxPage"/> <!-- 输出总记录数 -->

页 共有<bean:write name="pageNumber"/> <!-- 输出总分页 -->

条 当前为第<bean:write name="nonce"/>页 <!-- 输出当前页数 -->

<logic:equal name="nonce" value="1">

首页

</logic:equal>

<logic:notEqual name="nonce" value="1"> <!-- 如果当前页码不等于1 -->

<a href="peopleAction.do?i=0">首页</a> <!-- 提供首页超链接 -->

</logic:notEqual>


<logic:lessEqual name="maxPage" value="${nonce}"> <!-- 如果当前页码不小于总页数 -->

尾页 <!-- 不提供尾页超链接 -->

</logic:lessEqual>

<logic:greaterThan name="maxPage" value="${nonce}"> <!-- 如果当前页码小于总页数 -->

<a href="peopleAction.do?i=<%=maxPage-1%>">尾页</a> <!-- 提供尾页超链接 -->

</logic:greaterThan>

<logic:equal name="nonce" value="1"> <!-- 如果当前页码等于1 -->

上一页 <!-- 不提供上一页超链接 -->

</logic:equal>

<logic:notEqual name="nonce" value="1"> <!-- 如果当前页码不等于1 -->

<a href="peopleAction.do?i=<%=number-1%>">上一页</a> <!-- 提供上一页超链接 -->

</logic:notEqual>

<logic:lessEqual name="maxPage" value="${nonce}">

下一页

</logic:lessEqual>

<logic:greaterThan name="maxPage" value="${nonce}"> <!-- 如果当前页面小于总页数 -->

<a href="peopleAction.do?i=<%=number+1%>">下一页</a> <!-- 提供下一页超链接 -->

</logic:greaterThan>

</td>

</tr>

</table> </form></td>

</tr>

</table>

</body>

</html>