页码导航算法

int pcount = r3d.pager.getPageCount();

int curpage = r3d.pager.getPageNow();



if (pcount > 1) {//显示超链接

    //上一页

    if (curpage != 1) {

        out.println("<a href=index.jsp?pageNow=" + (curpage - 1)

                + ">上一页</a>");

        out.println("<a href=index.jsp?pageNow=1>[1]</a>");

    } else

        out.println("&nbsp;1&nbsp;");



    int stap = curpage - 2;

    int endp = curpage + 2;

    if (endp > pcount - 1)

        stap -= (endp - pcount + 1);

    if (stap < 2) {

        endp += (2 - stap);

        stap = 2;

    }



    int i = stap;



    if (i >  2) {

        out.println("...");

    }



    while (i <= endp && i <= pcount) {

        if (i == curpage)

            out.println("&nbsp;" + i + "&nbsp;");

        else

            out.println("<a href=index.jsp?pageNow=" + i + ">[" + i

                    + "]</a>");

        i++;

    }

    if (i < pcount) {

        out.println("...");



        out.println("<a href=index.jsp?pageNow=" + pcount + ">["

            + pcount + "]</a>");

    }

    //下一页

    if (curpage < pcount) {

        out.println("<a href=index.jsp?pageNow=" + (curpage + 1)

                + ">下一页</a>");

    }

}

 

你可能感兴趣的:(算法)