jsp分页查询模板

jsp分页查询模板
改改就能用

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<!-- 引入自定义css文件 style.css -->
<link rel="stylesheet" href="css/style.css" type="text/css" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>

<style>
	table{
		border:1px solid red;
		border-collapse:collapse;
		margin:auto;
		margin-top:100px;
	}
	tr,td{
		border:1px solid red;
		padding:10px;
	}
</style>
		
<body>
	<table>
			<tr>
				<td>编号</td>
				<td>姓名</td>
				<td>职位</td>
				<td>上司</td>
				<td>日期</td>
				<td>工资</td>
				<td>奖金</td>
				<td>部门编号</td>
			</tr>
			<c:forEach items="${pageBean.emp}" var="emp">
				<tr>
					<td>${emp.empno }</td>
					<td>${emp.ename }</td>
					<td>${emp.job }</td>
					<td>${emp.mgr }</td>
					<td>${emp.hiredate }</td>
					<td>${emp.sal }</td>
					<td>${emp.comm }</td>
					<td>${emp.deptno }</td>
				</tr>
			</c:forEach>
		</table>
		
		<!--分页 -->
		<div style="width: 380px; margin: 0 auto; margin-top: 50px;">
			<ul class="pagination" style="text-align: center; margin-top: 10px;">
					
				<c:forEach begin="1" end="${pageBean.totalPage}" var="page">
					<!-- 判断当前页 -->
					<c:if test="${pageBean.currentPage==page}">
						<li class="active"><a href="javascript:void(0);">${page}</a></li>
					</c:if>
					
					<c:if test="${pageBean.currentPage!=page}">
						<li><a href="${pageContext.request.contextPath}/findall?currentPage=${page}">${page}</a></li>
					</c:if>
				</c:forEach>
				
				<!--  
				<li class="disabled"><a href="#" aria-label="Previous"><span
						aria-hidden="true">&laquo;</span></a></li>
				<li class="active"><a href="#">1</a></li>
				<li><a href="#">2</a></li>
				<li><a href="#">3</a></li>
				<li><a href="#">4</a></li>
				<li><a href="#">5</a></li>
				<li><a href="#">6</a></li>
				<li><a href="#">7</a></li>
				<li><a href="#">8</a></li>
				<li><a href="#">9</a></li>
				<li class="disabled"><a href="#" aria-label="Next"> <span aria-hidden="true">&raquo;</span>
				</a></li>-->
			</ul>
		</div>
		<!-- 分页结束 -->
</body>
</html>

下面是后台分页代码

在这里插入代码片
int totalPage = (int)Math.ceil(1.0*totalcount/currentCount);
pageBean.setTotalPage(totalPage);
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FindAllServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		FindService findall=new FindService();
		PageBean pageBean=null;
		//模拟当前页是第一页
		String currentPage = request.getParameter("currentPage");
		if(currentPage==null){
			currentPage="1";
		}
		int parseInt = Integer.parseInt(currentPage);
		//认为每页显示12条
		int curretnCount=3;
		try {
			pageBean=findall.findPageBean(parseInt,curretnCount);
			request.setAttribute("pageBean", pageBean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.getRequestDispatcher("index.jsp").forward(request, response);	
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}

你可能感兴趣的:(CRUD)