第九步:前台处理页面。
由于后台传回来的是一个ArrayList的数据表,所以把它读出来就是。
所以要是想弄不同的“上一页”、“下一页”这样的导航条的话,修改传回的参数,再在Jsp页面里做相应的处理就OK了。
看我的Jsp页面:index.jsp
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<% if(session.getAttribute("getData")==null)
{//这里只是一个跳转,没什么
session.setAttribute("getData","ok");
response.setHeader("refresh",
"1;url=/strutsPage/productShow.do?pageDo=first&curr_page=1");
}
%>
<html>
<head>
<title>JSP for ProductShowForm form</title>
</head>
<body><font color="#0000ff">
这里仅演示分页,操作部分已经做到获取ID了,相信直接调用就可以弄修改和删除</font>
<table width="80%" border="1">
<tr>
<th>
商品名称
</th>
<th>
价格
</th>
<th>
商品描述
</th>
<th>
商品详细信息
</th>
<th >
上架日期
</th>
<th colspan="2" align="center">
操作
</th>
</tr>
<logic:present name="data" scope="request">
<logic:iterate id="show" name="data"
type="com.yourcompany.vo.Product">
<tr>
<td>
<bean:write name="show" property="name" />
</td>
<td>
<bean:write name="show" property="saleprice" />
</td>
<td>
<bean:write name="show" property="descript" />
</td>
<%--<td>
<bean:write name="show" property="contents" />
</td>
--%><td >
<bean:write name="show" property="saledate" />
</td>
<td>
<html:link action="/productShow.do?pageDo=updata"
paramId="up_page" paramName="show" paramProperty="id">
修改</html:link>
</td>
<td>
<html:link action="/productShow.do?pageDo=dele"
paramId="dele_page" paramName="show" paramProperty="id">
删除</html:link>
</td>
</tr>
</logic:iterate>
</logic:present>
</table>
<logic:present name="pageInfo">
第<bean:write name="pageInfo" property="curr" />页/共
<bean:write name="pageInfo" property="count" />页.
<html:link action="/productShow.do?pageDo=first"
paramId="curr_page" paramName="pageInfo" paramProperty="curr">
首页</html:link>
<logic:notEqual name="pageInfo" property="curr" value="1">
<html:link action="/productShow.do?pageDo=prv"
paramId="curr_page" paramName="pageInfo" paramProperty="curr">
上一页</html:link>
</logic:notEqual>
<logic:equal name="pageInfo" property="last" value="false">
<html:link action="/productShow.do?pageDo=next"
paramId="curr_page" paramName="pageInfo" paramProperty="curr">
下一页</html:link>
</logic:equal>
<html:link action="/productShow.do?pageDo=end"
paramId="curr_page" paramName="pageInfo" paramProperty="curr">
尾页</html:link>
</logic:present>
</body>
</html>
总结:
这个分页看起来很简单,做起来也很简单。只是对SQL语句做了一下过滤而已。这个分页功能很简单,但重在抛砖引玉!
更多内容请看PCdog.com--MySQL数据备份 数据库相关文章专题
