JSP页面中.分页显示的.前面还好..当上了了50条的时候就出现:java.lang.OutOfMemoryError: Java heap space
at java.lang.StringCoding$CharsetSD.decode(StringCoding.java:183)
at java.lang.StringCoding.decode(StringCoding.java:228)
at java.lang.String.<init>(String.java:405)内存错误了!
我是每次都查出来.然后每次显示一部分.这样肯定是有问题的.但是不这样.用SESSION也不行..
请问可以怎么样一次取出我想要的..

解决方案 »

  1.   

    建议你用一个分页辅助bean
    package cn.md.util;
    /**
     * <pre>
     * 分页类
     * </pre>
     *
     * <ul>处理分页的基本信息</ul>
     * <ul>
     * 处理分页的基本信息.<br>
     * </ul>
     * <br/>
     */
    public class PageBean { /* 分页大小 */
    private int pageRecorders = 10;

    /** 前一页 */
    private int previousPage;
    /** 后一页 */
    private int nextPage;
    /** 当前页 */
    private int currentPage;
    /** 总页数 */
    private int totalPages;
    /** 总记录数 */
    private int totalRecorders;
    /** 是否有下一页 */
    private boolean hasNextPage = false;
    /** 是否有前一页 */
    private boolean hasPreviousPage = false; /**
     * 构造方法.
     * <ul>
     * 构造方法1,每页大小为2,测试用。
     * </ul>
     * @param currentPage int
     * @param totalRecorders int
     */
    public PageBean(int currentPage, int totalRecorders) {
    this.currentPage = currentPage;
    this.totalRecorders = totalRecorders;
    //计数总共的页数
    if ( (totalRecorders % pageRecorders) == 0) {
    this.totalPages = totalRecorders / pageRecorders;
    } else {
    this.totalPages = totalRecorders / pageRecorders + 1;
    }
    if(this.totalPages<=0){
    this.totalPages=1;
    }
    //处理不合法的当前页
    if (this.currentPage >= this.totalPages) {
    this.currentPage = this.totalPages;

    }
    if (this.currentPage <= 1) {
    this.currentPage = 1;
    }
    //是否有下一页
    if (this.currentPage >= this.totalPages) {
    this.hasNextPage = false;
    } else {
    this.hasNextPage = true;
    }
    //是否有上一页
    if ( this.currentPage == 1 ) {
    this.hasPreviousPage = false;
    } else {
    this.hasPreviousPage = true;
    }
    this.nextPage=this.currentPage+1;
    this.previousPage=this.currentPage-1;
    } /**
     * 构造方法.
     * <ul>
     * 构造方法2
     * </ul>
     * @param currentPage int
     * @param totalRecorders int
     */
    public PageBean(int currentPage, int totalRecorders, int pageSize) {
    this.currentPage = currentPage;
    this.totalRecorders = totalRecorders;
    this.pageRecorders = pageSize;
    //计数总共的页数
    if ( (totalRecorders % pageSize) == 0) {
    this.totalPages = totalRecorders / pageSize;
    } else {
    this.totalPages = totalRecorders / pageSize + 1;
    }
    //处理不合法的当前页
    if (this.currentPage > this.totalPages) {
    this.currentPage = this.totalPages;
    }
    if (this.currentPage < 1) {
    this.currentPage = 1;
    }
    //是否有下一页
    if (this.currentPage >= this.totalPages) {
    this.hasNextPage = false;
    } else {
    this.hasNextPage = true;
    }
    //是否有上一页
    if ( this.currentPage == 1 ) {
    this.hasPreviousPage = false;
    } else {
    this.hasPreviousPage = true;
    }
    this.nextPage=this.currentPage+1;
    this.previousPage=this.currentPage-1;
    } /**
     * 返回当前页
     * @return int
     */
    public int getCurrentPage() {
    return currentPage;

    }
    /**
     * 返回总页数
     * @return int
     */
    public int getTotalPages() {
    return totalPages;
    }
    /**
     * 返回总的记录数
     * @return int
     */
    public int getTotalRecorders() {
    return totalRecorders;
    }
    /**
     * 返回是否有下一页
     * @return boolean
     */
    public boolean isHasNextPage() {
    return hasNextPage;
    }
    /**
     * 返回是否有上一页
     * @return boolean
     */
    public boolean isHasPreviousPage() {
    return hasPreviousPage;
    } /**
     * 返回每页的记录数
     * @return int
     */
    public int getPageRecorders() {
    return pageRecorders;
    } public int getPreviousPage() {
    return previousPage;
    } public void setPreviousPage(int previousPage) {
    this.previousPage = previousPage;
    } public int getNextPage() {
    return nextPage;
    } public void setNextPage(int nextPage) {
    this.nextPage = nextPage;
    }
    }