经过奋战,终于实现了在JSP中使用标准标签库实现记录分页显示,JSP代码为:
<%@ page language="java"
import="java.util.*,logicprocess.ProductBean,logicprocess.PageControl"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>商品信息</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">
<link rel="stylesheet" type="text/css" href="../common/css/bg1.css">
</head>
<body>
<center>
<h3>============所有商品的信息============</h3>
<hr>
<%
String currentPage=request.getParameter("pageIndex");
if(currentPage==null)
currentPage="1";
int pageIndex=Integer.parseInt(currentPage);
ProductBean v=new ProductBean();
ArrayList list=v.getAllProduct();
PageControl pc = (PageControl)request.getAttribute("pc");
if(pc == null){
pc = new PageControl();
}
pc.setBigList(list);
request.setAttribute("pc",pc);
pc.setCurrentPage(pageIndex);
%>
<form action="viewProduct.jsp" method="POST">
<table bgcolor="#FFDEAD" border="1" width="646">
<tr><td >共有<%=pc.getPageSize()%>页
当前第<%=pageIndex%>页 </td>
<td > <a href="viewProduct.jsp?pageIndex=1">首页</a>
<c:if test="${pc.previousPageCount > 0}" var="true">
<a href="viewProduct.jsp?pageIndex=${pc.previousPageCount}">上一页</a>
</c:if>
<c:if test="${ pc.nextPagecount <= pc.pageSize}" var="true">
<a href="viewProduct.jsp?pageIndex=${pc.nextPagecount}">下一页</a>
</c:if>
<a href="viewProduct.jsp?pageIndex=${pc.pageSize}">尾页</a>
导航:
<input type="text" name="pageIndex" size="10">
<input type="submit" name="submit" value="GO" >
</td></tr>
</table>
</form>
<table bgcolor="#E0FFFF" border="1">
<tr> <td align="center">产品 ID</td><td align="center">名 称</td>
<td align="center">产品类别ID</td><td align="center">价 格</td>
<td align="center">数 量</td><td align="center">入库时间</td><td align="center">产品描述</td>
<td align="center">更 改</td><td align="center">删 除</td>
</tr>
<c:forEach var="vc" items="${pc.smallList}">
<tr>
<td><c:out value="${vc.productId}"/></td>
<td><c:out value="${vc.name}"/></td>
<td><c:out value="${vc.categoryId}"/></td>
<td><c:out value="${vc.price}"/></td>
<td><c:out value="${vc.amount}"/></td>
<td><c:out value="${vc.storeTime}"/></td>
<td><c:out value="${vc.describe}"/></td>
<td><a href='modifyProduct.jsp?paramm=${vc.productId}'><font color="#0000FF">更改</font></a></td>
<td><a href='deleteProduct.jsp?paramm=${vc.productId}'><font color="#FF0000">删除</font></a></td>
<td><br></td>
</tr>
</c:forEach>
</table>
<h3><a href="index.jsp"><font color="red" size="+1">Go back</font></a></h3>
</center>
</body>
</html>
效果图: