采用MVC方式开发时,将数据库查询的记录集放入ArrayList对象中,在显示的页面将ArrayList对像展示成表格形式,当使用分页时,由于ArrayList对象是在request中的,所以用<href a >时本页面会失效,真是个难题。
<%
ArrayList rptdata = (ArrayList)request.getAttribute("rptdata");
%>
<%
Iterator data = rptdata.iterator();
int pnum=1;//页码
int pagesize=1; //每页20个记录
String strPage = request.getParameter("page");
if(strPage!=null)
{
pnum=Integer.parseInt(strPage);
}
double pcount =rptdata.size()/pagesize;
int pageCount=1;
if(pcount>1)
{
pageCount=(int)Math.ceil(rptdata.size()/pagesize);
}
out.println("pcount=="+pcount);
int line = 1;
int line1 = (pnum-1)*pagesize+1;
int line2 = pnum*pagesize;
//out.println("line1=="+line1);
//out.println("line2=="+line2);
double hj=0d;
while(data.hasNext() )
{
gwList gw = (gwList)data.next();
if (line>=line1 && line<=line2)
{
%>
<tr>
<td width="34"><%=line%> </td>
<td width="140"><%=gw.getInst_name()%> </td>
<td width="88"><%=gw.getApp_name()%> </td>
<td width="39" align="center"><%=gw.getApp_sex()%> </td>
<td width="91"><%=gw.getApp_userid()%> </td>
<td width="107" align="center"><%=gw.getApp_job()%> </td>
<td width="69" align="right"><%=gw.getMonth_earning()%> </td>
<td width="67" align="right"><%=gw.getFamily_pop()%> </td>
<td width="58" align="right"><%=gw.getFamily_mon_earning()%> </td>
<td width="71" align="center"><%=gw.getIf_SS()%> </td>
<td width="55" align="center"><%=gw.getIf_city()%> </td>
<td width="101" align="right"><%=gw.getAllo_money()%> </td>
<td width="50" align="center"><%=gw.getStaff_type()%> </td>
</tr>
<%
}
hj+=gw.getAllo_money();
line++;
}
%>
<tr>
<td width="174" colspan="2">
<p align="center">合计</td>
<td width="796" colspan="11">
<p align="center">共计<%=(--line)%>人,金额共计<%=hj%>元。</td>
</tr>
</table>
<div style="float:left;clear:right">第<%=pnum%>页 共<%=pageCount%>页 <%if(pnum>1) {%><a href=<%=request.getRequestURL()%>?page=<%=(pnum-1)%>>上一页</a><%}%><%if(pnum<pageCount) {%><a href=<%=request.getRequestURL()%>?page=<%=(pnum+1)%>>下一页</a><%}%></div>本文来自爪式千斤顶:http://www.qizejx.com
有关java中采用List 分页技术问题
最新推荐文章于 2024-08-30 18:40:43 发布