当前位置: 代码迷 >> Java Web开发 >> 关于分页有关问题的求解
  详细解决方案

关于分页有关问题的求解

热度:160   发布时间:2016-04-16 21:59:13.0
关于分页问题的求解。
小生做了一个分页,通过连接池链接mysql,在Page.java 里写了分页的代码。是一个简要的查询系统来的。分页完成了,可以查询数据,但是数据显示的页面却没有按照分页显示,上一页 下一页 首页 尾页等等均可点击,但是点击后均无数据显示。
总记录数和总页数一直显示为0.求各位大神解答。小生把代码贴出来。跪求完整代码,如何修改。

这个是显示结果页面 
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="bean.Page" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
String currentPage = request.getParameter("currPage");
String action = request.getParameter("action");
        String totalPage=request.getParameter("totalPage");
        String totalRows=request.getParameter("totalRows");
        
int currPage = 1;
if(currentPage !=null){
currPage = Integer.parseInt(currentPage);
}
Page p = new Page();
if(action!=null){
if(action.equals("before")){
p.beforePage();
}
if(action.equals("next")){
p.nextPage();
}
}
out.println(p.getCurrentPage());
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <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="styles.css">
-->

  </head>
  
  <body>

  <table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px;font-size:12px">
<tr bgcolor="#E7E7E7">
    <td> <height="24" colspan="10" background="/images/heart.jpg" style="font-size: 14px;font-weight: bold;">&nbsp;查询结果&nbsp;</td>
</tr>
<tr> <align="center" bgcolor="#FAFAF1" height="22"></tr>>
        <td  width="25%">编号</td>
      <td align="25%">视频名称</td>
      <td align="25%">出版时间</td>
       <td align="25%">制作单位</td>
      <td align="25%">出版单位</td>
    </tr>
    <c:forEach var="me" items="${list}" varStatus="sta">
        <tr><align="center" bgcolor="#FFFFFF" height="22" >
      
        <td>${me.id }</td>
<td>${me.name }</td>
<td>${me.time }</td>

       
</tr>

</c:forEach>
</table>
      
    <jsp:useBean id="linkPage" class="bean.Page" scope="page">
  <%
      Page.class.setTotalRows(100);
   linkPage.setHasBefore(true);
   linkPage.setHasNext(true);
   linkPage.setPageSize(3);
   linkPage.setPageURL("query.jsp");
  
   %>
   <jsp:getProperty property="linkHTML" name="linkPage"/><br>
   <jsp:getProperty property="currentPage" name="linkPage"/>
   </jsp:useBean>
  </body>
</html>


这个是page.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;
import java.util.Calendar;
/**
 *
 * @author Lenovo
 */
public class Page {
        private int pageSize = 3; //每页显示的记录数
private int currentPage = 1; //当前页
private int totalPage = 0; //总页数
private int totalRows = 0; //总记录数
private boolean hasBefore = false; //是否有上一页
private boolean hasNext = false ; //是否有下一页
private String linkHTML=""; //用于保存分页导航的HTML代码
private String pageURL; //具体的链接地址
  相关解决方案