JSP realizes simple paging function __js

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}"/>
&LT;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} ';
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.