jsp實現簡單分頁功能__js

來源:互聯網
上載者:User
一.webcontend層
1.webcontent/common/meta.jsp

代碼:
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

2.webcontent/page/page.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/ WEB-INF /c.tld" prefix="c"%>
<c:set var="page" value="${sessionScope.page}" />
<c:set var="path" value="${pageContext.request.contextPath}" />
<c:set var="url" value="${param.url}" />
<c:set var="urlParams" value="${param.urlParams}" />
<c:set var="pathurl" value="${path}/${url}" />
<tr align="center">
共${page.totalCount}條記錄 共${page.totalPage}頁 每頁顯示${page.everyPage}條
當前第${page.currentPage}頁
<c:choose>
<c:when test="${page.hasPrePage eq false}">
<<首頁 <上頁
</c:when>
<c:otherwise>
<a href="${pathurl}?&pageAction=first${urlParams}"><<首頁 </a>
<a href="${pathurl}?pageAction=previous${urlParams}" /><上一頁</a>
</c:otherwise>
</c:choose>
||
<c:choose>
<c:when test="${page.hasNextPage eq false}">
下頁> 尾頁>>
</c:when>
<c:otherwise>
<a href="${pathurl}?&pageAction=next${urlParams}">下一頁> </a>
<a href="${pathurl}?pageAction=last${urlParams}" />末頁>></a>
</c:otherwise>
</c:choose>

<SELECT name="indexChange" id="indexChange"
onchange="getCurrentPage(this.value);">
<c:forEach var="index" begin="1" end="${page.totalPage}" step="1">
<option value="${index}" ${page.currentPage eq index ? "selected" : ""}>
第${index}頁
</option>
</c:forEach>
</SELECT>

每頁顯示:<select name="everyPage" id="everyPage" onchange="setEveryPage(this.value);">
<c:forEach var="pageCount" begin="5" end="${page.totalCount}" step="5">
<option value="${pageCount}" ${page.everyPage eq pageCount ? "selected" : ""}>
${pageCount}條
</option>
</c:forEach>
</select>
</tr>
<div style='display: none'>
<a class=listlink id="indexPageHref" href='#'></a>
</div>
<script>
function getCurrentPage(index){
var a = document.getElementById("indexPageHref");
a.href = '${pathurl}?pageAction=gopage&pageKey='+index+'${urlParams}';
a.setAttribute("onclick",'');
a.click("return false");
}
function setEveryPage(everyPage){
var a = document.getElementById("indexPageHref");
var currentPage = document.getElementById('indexChange').value;
a.href = '${pathurl}?pageAction=setpage&pageKey='+everyPage+'${urlParams}';
a.setAttribute("onclick",'');
a.click("return false");
}
function sortPage(sortName){
var a = document.getElementById("indexPageHref");
a.href = '${pathurl}?pageAction=sort&pageKey='+sortName+'${urlParams}';
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.