• jsp分页


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ include file="/decorators/includes/taglibs.jsp"%>
    <!-- 
        ectable样式的分页
     -->
    <script type="text/javascript">
    <!--
        function toPage(pageNum){
            $("#pageNum").val(pageNum);
            $("#qform").submit();
        }
        function goPage(){
            if(isNaN($("#_page_No_").val())){
                alert("页码不正确");
                return;
            }
            toPage($("#_page_No_").val()-1);
        }
    //-->
    </script>
    <table border="0" cellspacing="0" cellpadding="0" class="tableRegion" width="100%">
    <tbody>
        <tr style="padding: 0px;">
            <td style="border: 0px solid #CCC;">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tbody>
                        <tr>
                            <td class="statusBar" align="center"><span style="color: red">${totalCount }</span> 条记录, 
                                当前显示 <span style="color: red">${totalCount==0?0:pageSize*(pageNum-1)+1 }</span><span style="color: red">
                                    <c:choose>
                                        <c:when test="${pageSize*pageNum > totalCount }">${totalCount }</c:when>
                                        <c:otherwise>${pageSize*pageNum }</c:otherwise>
                                    </c:choose>
                                </span>&nbsp;&nbsp;&nbsp;&nbsp;
                                <c:if test="${totalPage > 1 }">
                                    <c:choose>
                                        <c:when test="${pageNum > 1 }">
                                            <span onclick="toPage(${pageNum - 2 })" style="margin: 4px;cursor:pointer;" title="上一页">上一页</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span style="margin: 4px;">上一页</span>
                                        </c:otherwise>
                                    </c:choose>
                                    
                                    <!-- 显示中间的页数 -->
                                    <c:choose>
                                        <c:when test="${totalPage <= 10}">
                                            <c:forEach var="indexNo" begin="1" end="${totalPage}">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </c:when>
                                        <c:when test="${pageNum < 10 && totalPage > 10}">
                                            <c:forEach var="indexNo" begin="1" end="10">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                            <span style="margin: 4px;color:red">...</span>
                                            <span onclick="toPage(${totalPage-1})" style="margin: 4px;cursor:pointer;">${totalPage}</span>
                                        </c:when>
                                        <c:when test="${pageNum >= 10 && pageNum < totalPage-1}">
                                            <span onclick="toPage(0)" style="margin: 4px;cursor:pointer;">1</span>
                                            <span style="margin: 4px;color:red">...</span>
                                            <c:forEach var="indexNo" begin="${pageNum-7 }" end="${pageNum+2 }">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                            <c:if test="${(pageNum+2) < totalPage }">
                                                <span style="margin: 4px;color:red">...</span>
                                                <span onclick="toPage(${totalPage-1})" style="margin: 4px;cursor:pointer;">${totalPage}</span>
                                            </c:if>
                                        </c:when>
                                        <c:otherwise>
                                            <span onclick="toPage(0)" style="margin: 4px;cursor:pointer;">1</span>
                                            <span style="margin: 4px;color:red">...</span>
                                            <c:forEach var="indexNo" begin="${totalPage-9 }" end="${totalPage }">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </c:otherwise>
                                    </c:choose>
                                    <!-- 显示中间的页数 结束 -->
                                    
                                    <c:choose>
                                        <c:when test="${totalPage > 1 && pageNum < totalPage}">
                                            <span onclick="toPage(${pageNum })" style="margin: 4px;cursor:pointer;" title="下一页">下一页</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span style="margin: 4px;">下一页</span>
                                        </c:otherwise>
                                    </c:choose>
                                    <input type="text" style=" 20px; height: 16px; margin-right: 4px;" id="_page_No_" value="${pageNum }">
                                    <button onclick="goPage()" style="height: 20px;">GO</button>
                                </c:if>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>        
    </tbody>
    </table>

    效果如下:

  • 相关阅读:
    使用JMeter进行RESTful API测试
    DVWA reCAPTCHA key: Missing
    SQL注入之DVWA平台测试mysql注入
    DVWA之SQL注入演练(low)
    浅谈CSRF攻击方式
    WAMPSERVER-服务器离线无法切换到在线状态问题的解决
    SQL注入攻击和防御
    WebScarab安装
    Intellij idea 自动完成的变量名称首字母变为小写
    在IDEA中代码自动提示第一个字母大小写必须匹配的解决
  • 原文地址:https://www.cnblogs.com/yushouling/p/5036417.html
Copyright © 2020-2023  润新知