当前位置:编程学习 > JSP >>

jsp分页

  jsp分页

public int doStartTag() throws JspException {
        StringBuffer sb = null;
        if (result != null && result.getContent() != null
                && result.getContent().size() > 0) {
            sb = new StringBuffer("分页: ");
            if (result.getPage().getHasPrePage()){
                sb.append("<a href='").append(url);
                if (url.indexOf("?") == -1)
                    sb.append("?page=1");
                else
                    sb.append("&page=1");
                linkParams(sb);
                sb.append("'>").append("首页").append("</a>").append(" | ");
                sb.append("<a href='").append(url);
                if (url.indexOf("?") == -1)
                    sb.append("?page=").append(
                            result.getPage().getPreviousPage());
                else
                    sb.append("&page=").append(
                            result.getPage().getPreviousPage());
                linkParams(sb);
                sb.append("'>").append("上页").append("</a>").append(" | ");
            }
            if (result.getPage().getHasNextPage()) {
                sb.append("<a href='").append(url);
                if (url.indexOf("?") == -1)

 


                    sb.append("?page=").append(result.getPage().getNextPage());
                else
                    sb.append("&page=").append(result.getPage().getNextPage());
                linkParams(sb);
                sb.append("'>").append("下页").append("</a>").append(" | ");
                sb.append("<a href='").append(url);
                if (url.indexOf("?") == -1)
                    sb.append("?page=").append(result.getPage().getTotalPage());
                else
                    sb.append("&page=").append(result.getPage().getTotalPage());
                linkParams(sb);
                sb.append("'>").append("尾页").append("</a>");
            }
            sb
                    .append(" 跳转到:<select name='goToPage' onchange='javascript:goPage(this.value)'>");
            int s = result.getPage().getTotalCount();

 


            for (int i = 1; i <= s; i++) {
                sb.append("<option value=").append(i);
                if (Integer.parseInt(page) == i)
                    sb.append(" selected");
                sb.append(">第").append(i).append("页</option>");
            }
            sb.append("</select>");
            sb.append("<script language=javascript>");
            sb.append("function goPage(page){").append("window.location='")
                    .append(url);
            if (url.indexOf("?") == -1)
                sb.append("?page='+").append("page");
            else
                sb.append("&page='+").append("page");
            sb.append("+'");
            linkParams(sb);
            sb.append("';");

补充:Jsp教程,Application与Applet
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,