分页代码

<%!
int totalPages;         //总页数 变量
int countPerPage=5;    //计数 每页显示文章数 变量
int totalCount;        //信息总计数 变量
int currentPage=1;      //当前第几页面,赋值为1 变量
int currentStart;
%>
<%
ArrayList vt=memoQuery.dbQueryMemos();  //通过DatabaseBean类中的dbQueryMemos()方法搜索查询数据库
totalCount=vt.size();   //数据库中存储信息的数量(size属性)
totalPages=totalCount/countPerPage;  // 总页数=存储信息总数量/每页显示文章数
if(totalCount%countPerPage>0)totalPages=totalPages+1;  // 余数大于0(或不等于0),则totalPages+1才是总页数
if(request.getParameter("page")==null)  
{
currentPage=1;
}
else
{
currentPage=Integer.parseInt(request.getParameter("page"));

if(currentPage>totalPages)currentPage=totalPages; 

if(currentPage<1)currentPage=1;
}
currentStart=totalCount-1-countPerPage * (currentPage-1);
%>

<script language="JavaScript" >
function page_check()
{
if(document.pageForm.page.value=="")
{alert("请输入页数");
document.pageForm.page.focus();
return false;
}
return true;
}</script>

<center>
   //数据的分页显示
              <%
    
    for(int i=0;i<countPerPage&&currentStart-i>=0;i++)
    {
     memoInfo.setId(((MemoBean)vt.get(currentStart-i)).getId());
     memoInfo.setTitle(((MemoBean)vt.get(currentStart-i)).getTitle());     
     memoInfo.setContent(((MemoBean)vt.get(currentStart-i)).getContent());
     memoInfo.setUdate(((MemoBean)vt.get(currentStart-i)).getUdate());
     
     
   out.print("<table width='100%' border='1' ><tr><td width='18%'>"); 
   out.print(memoInfo.getTitle()); 
   out.print("</td><td height='30' colspan=''>");
   out.print(memoInfo.getContent());
   out.print("</td><td width='15%'>");
   out.print(memoInfo.getUdate());  
   out.print("</td></tr></table> ");
   out.print("<br>");
     
    }
  
   %>


   <form name="pageForm" method="post"  onSubmit="return page_check()" action="liuyan.jsp">
   <table style="width:100%; border:1; bordercolor:#0099CC">                              
                <tr> 
                    <td width="40%"></td>
                  <td width="4%">页码:<%out.print(currentPage);%>/<%out.print(totalPages);%></td>
                  <td width="5%">共<%out.print(totalCount);%>个留言</td>
                    <td width="12%">
                        <input type="button" value="首页" οnclick="javascript:window.location.href ='liuyan.jsp?page=1';">
                        <input type="button" value="上一页" οnclick="javascript:window.location.href ='liuyan.jsp?page=<%=currentPage-1%>';">
                        
                        <input type="button" value="下一页" οnclick="javascript:window.location.href ='liuyan.jsp?page=<%=currentPage+1%>';">
                        <input type="button" value="尾页" οnclick="javascript:window.location.href ='liuyan.jsp?page=<%=totalPages%>';">    
                    </td>
                    <td width="10%">
                        <input type="submit" name="Submit" value="G0">                    
                        <input name="page" type="text" size="10"> 页
                      </td>
                </tr>
              </table></form>
                  
                   </center>     
                                                                                               
           <table width="100%" border="0">
          <tr> 
            <td height="12" align="center">Copyright @ HomeLee. All rights reserved. 
            </td>
          </tr>
          <tr> 
            <td height="12" align="center" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
        </table>   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值