jsp + oracle翻页

今天写了个利用oracle sql在jsp页面进行分页。具体实现核心代码如下:

// 声明分页变量并初始化
    
// 当前页码值,最小索引值:1
     int  pageNo  =   1 ;
    
// 每页面显示的资讯条数(行数)
     int  row  =   10 ;
    
// 最大显示页数
     int  MAX_PAGE_NUM = 20 ;
    
// 最大每页显示条数
     int  MAX_ROWCOUNT = 20 ;
    
    
// 从请求中获取分页变量的值
    String reqNo = request.getParameter( " pageNo " );
    String reqRow
= request.getParameter( " row " );
    
if ( ! StringUtils.isEmpty(reqNo)  &&  NumberUtils.isNumber(reqNo)  &&  Integer.parseInt(reqNo) > 1 ) {
        
//分页数不超过 MAX_PAGE_NUM 页,若需要超过 MAX_PAGE_NUM 页,则修改 MAX_PAGE_NUM
        if(Integer.parseInt(reqNo)<=MAX_PAGE_NUM)
            pageNo
=Integer.parseInt(reqNo);
        
else
            pageNo
=MAX_PAGE_NUM;
    }

    
if ( ! StringUtils.isEmpty(reqRow)  &&  NumberUtils.isNumber(reqRow)  &&  Integer.parseInt(reqRow) > 1 ) {
        
//每页显示的条目在 MAX_ROWCOUNT 行以内,若需要超过 MAX_ROWCOUNT 行,则修改 MAX_ROWCOUNT
        if(Integer.parseInt(reqRow)<=MAX_ROWCOUNT)
            row
=Integer.parseInt(reqRow);
        
else
            row
=MAX_ROWCOUNT;
    }

    
    
int  startNum = (pageNo  -   1 *  row;

 以上代码嵌入在jsp页面里,然后sql语句如下:

List list = service.executeQuery(" select  kpj,spj,zd  from  ( select  kpj,spj,zd,ROWNUM R  from  gazx.qhhq  where  pz  like   ' %"+param+"% '   and +
                    " zhxgrq
= ( select   max (zhxgrq)  from  gazx.qhhq)  and  scbz = 0   and  gkbz = 1   and  rownum <= " + (startNum + row) + ")  where  R > " + startNum + "");

 接下来进行分页联接:

                     // 处理分页链接
                     if (pageNo < MAX_PAGE_NUM)
                        out.println(
" <a href='qhList.jsp? " + paras + " &amp;pageNo= " + (pageNo + 1 ) + " &amp;row= " + row + " '>下页</a>&nbsp; " );
                    
if (pageNo > 1 )
                        out.println(
" <a href='qhList.jsp? " + paras + " &amp;pageNo= " + (pageNo - 1 ) + " &amp;row= " + row + " '>上页</a>&nbsp; " );
                    out.println(
" <a href='qhList.jsp? " + paras + " &amp;pageNo=1&amp;row= " + row + " '>首页</a>&nbsp; " );
                    out.println(
" <a href='qhList.jsp? " + paras + " &amp;pageNo= " + MAX_PAGE_NUM + " &amp;row= " + row + " '>末页</a><br/> " );
                    out.println(
" " + pageNo + " / " + MAX_PAGE_NUM + " 页<br/> " );

你可能感兴趣的:(jsp + oracle翻页)