日期:2014-05-17  浏览次数:20674 次

求助:我的分页查询变成了个死循环
程序开始运行会到PageHouse 的serviet中去开始查找第一页数据,可是到了最后把查到的集合放到request的Attribute中在跳转回去的时候,就一直查数据!就是不跳转!我真的不知道怎么会事了!
Java code
 List<House>    houseList  = houseManager.pageQueryHouse(pageIndex,pageSize);
        request.setAttribute("houses", houseList);
       // System.out.println(houses.get(1).getName());
        request.getRequestDispatcher("page/search_list.jsp").forward(request, response);


我就查询了一次,去掉 request.setAttribute("houses", houseList);就可以正常往下走!
下面是它一直查数据的Sql
Hibernate:
SQL code
select * from ( select house0_.ID as ID3_, house0_.NAME as NAME3_, house0_.USERS_ID as USERS3_3_, house0_.TYPE_ID as TYPE4_3_ from HOUSES house0_ ) where rownum <= ?


------解决方案--------------------
可是到了最后把查到的集合放到request的Attribute中在跳转回去的时候,就一直查数据!

这句不好理解。
------解决方案--------------------
Java code






我用分页不是把页号作为数据记录的一项,是把数据取出来然后根据每页显示的条数计算出来有多少页,我的方法参考下吧,不知道是不是你想要的结果:
Java code

ListAction.java



package com.sy.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.sy.dao.AdminDao;
import com.sy.dao.NewsDao;
import com.sy.dao.impl.AdminDaoImpl;
import com.sy.dao.impl.NewsDaoImpl;
import com.sy.vo.Admin;
import com.sy.vo.News;

public class ListAction extends ActionSupport {

    private static final long serialVersionUID = 1L;
        int i=1;//中间变量
    private int k;//储存最大页面数
    private int pageNow=1; //页码数,初始为1
    private int pageSize = 5 ; //页面行数 
    private int intRowCount;//总行数
    private int intPageCount;//总页数
    private Admin admin;
    private List<Admin> Adminss;
    private News news;
    @SuppressWarnings("unchecked")
    private List<News> Newss;
    
    private int id;
    private int aid;

    public News getNews() {
        return news;
    }

    public void setNews(News news) {
        this.news = news;
    }

    @SuppressWarnings("unchecked")
    public List<News> getNewss() {
        return Newss;
    }
    public void setNewss(List<News> newss) {
        Newss = newss;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public List<Admin> getAdminss() {
        return Adminss;
    }

    public void setAdminss(List<Admin> adminss) {
        Adminss = adminss;
    }
    public int getAid() {
        return aid;
    }

    public void setAid(int aid) {
        this.aid = aid;
    }

    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getIntRowCount() {
        return intRowCount;
    }

    public void setIntRowCount(int intRowCount) {
        this.intRowCount = intRowCount;
    }

    public int getIntPageCount() {
        return intPageCount;
    }

    public void setIntPageCount(int intPageCount) {
        this.intPageCount = intPageCount;
    }
    public int getK() {
        return k;
    }

    public void setK(int k) {
        this.k = k;
    }
@SuppressWarnings("unchecked")
    @Override
//显示新闻列表
    public String execute() throws Exception {

        NewsDao npage=new NewsDaoImpl();
        intRowCount=npage.count();
        k=(intRowCount + pageSize - 1) / pageSize;
        intPageCount = (intRowCount + pageSize - 1) / pageSize;//计算出总页数
        if(pageNow<1){
            pageNow=1;
        }
        
        if(pageNow > intPageCount)
             pageNow=intPageCount;
             i = (pageNow -1)*pageSize;
        New