您的位置:首页 > 其它

jdbc:客户信息管理案例:页面数据封装和公用页面处理类

2014-06-29 00:00 543 查看
数据封装:

public class Page {
private int pageNum;//当前页码 传入
private int pageSize=5;//每页显示的记录条数
private int totalPage;//总页数 计算
private int startIndex; //当前页码开始的索引 计算
private List records;//每页显示的记录 dao
private int totalRecords;//总记录条数 dao
private String servletUrl;
public Page(int pageNum,int totalRecords){
this.pageNum=pageNum;
this.totalRecords=totalRecords;
totalPage=totalRecords%pageSize==0?totalRecords/pageSize:totalRecords/pageSize+1;
startIndex=(pageNum-1)*pageSize;
}
public int getPageNum() {
return pageNum;
}
public String getServletUrl() {
return servletUrl;
}
public void setServletUrl(String servletUrl) {
this.servletUrl = servletUrl;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public List getRecords() {
return records;
}
public void setRecords(List records) {
this.records = records;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
}

公用页面:

page.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
第${page.pageNum}页   共${page.totalPage}页
<a href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num=1">首页</a>
<a href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num=${page.pageNum-1<1?1:page.pageNum-1}">上一页</a>
<a href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num=${page.pageNum+1>page.totalPage?page.totalPage:page.pageNum+1}">下一页</a>
<a href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num=${page.totalPage}">尾页</a>
<input type="text" name="num" id="num" value="${page.pageNum}" />
<a href="javascript:jump()">跳转</a>

<!-- 下拉方式跳转页码
<select name="num" id="id" onchange="jump(this)">
<c:forEach begin="1" end="${page.totalPage}" var="n">
<option value="${n}">${n}</option>
</c:forEach>
</select>
<script type="text/javascript">
function jump(selectObj){
window.location.href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num="+selectObj.value;
}
</script>
-->
<script type="text/javascript">
function jump(){
var num=document.getElementById("num").value;
var regObj=new RegExp("[1-9][0-9]*");
if(!regObj.test(num)){
alert("请输入自然整数");
return;
}
if(num>${page.totalPage}){
alert("超出范围");
return;
}
window.location.href="${pageContext.request.contextPath }/servlet/Controller?op=showAllCustomers&num="+num;
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐