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}';