JSP realizes simple paging function __js
Last Update:2018-07-26
Source: Internet
Author: User
I. Webcontend layer
1.webcontent/common/meta.jsp
Code:
<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" >
A total of ${page.totalcount} records a total of ${page.totalpage} page display ${page.everypage each page
Current First ${page.currentpage} page
<c:choose>
<c:when test= "${page.hasprepage eq false}" >
<< Home < prev
</c:when>
<c:otherwise>
<a href= "${pathurl}?&pageaction=first${urlparams}" ><< Home </a>
<a href= "${pathurl}?pageaction=previous${urlparams}"/>< previous page </a>
</c:otherwise>
</c:choose>
||
<c:choose>
<c:when test= "${page.hasnextpage eq false}" >
Next page > End >>
</c:when>
<c:otherwise>
<a href= "${pathurl}?&pageaction=next${urlparams}" > next page > </a>
<a href= "${pathurl}?pageaction=last${urlparams}"/> last page >></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": ""}>
Page ${index}
</option>
</c:forEach>
</SELECT>
Each page shows: <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} Bar
</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} ';