查询分页技术实现代码

由于代码比较多项目开发模型层的代码就不贴了

下面是jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'listAdmins.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <div align="center">
	    <div>
	    	<h1>显示数据</h1>
	    	<table border="1px"cellpadding="0"cellspacing="0">
	    		<thead>
	    			<tr>
	    				<th>序号</th>
	    				<th>姓名</th>
	    				<th>密码</th>
	    				<th>性别</th>
	    				<th>年龄</th>
	    				<th>操作</th>
	    				
	    			</tr>
	    		</thead>
	    		<tbody>
	    		<c:forEach items="${entities}" var="entity">
	    			<tr>
    					<td>${entity.id}</td>
    					<td>${entity.name}</td>
    					<td>${entity.pass}</td>
    					<td>${entity.sex}</td>
    					<td>${entity.age}</td>
    					<td>
    						<a href="#">修改</a>
    						<a href="#">删除</a>
    					</td>
	    			</tr>
	    			
	    		</c:forEach>
	    		</tbody>
	    	</table>
	    </div>
	    <div>
	    	<span><a href="${pageContext.request.contextPath}/listAdmins.do?">首页</a></span>
	    	<span><a href="${pageContext.request.contextPath}/listAdmins.do?nowpage=${nowpage-1}">上一页</a></span>
	    	<span><a href="${pageContext.request.contextPath}/listAdmins.do?nowpage=${nowpage+1}">下一页</a></span>
	    	<span><a href="${pageContext.request.contextPath}/listAdmins.do?nowpage=${countPage}">末页</a></span>
	    	<span>总记录数:${counRecord}总页数:${countPage}当前页:${nowpage}</span>
	    </div>
    </div>
   
    
    
  </body>
</html>

servlet:

package cn.csdn.web.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.csdn.web.domain.Admin;
import cn.csdn.web.service.AdminService;
import cn.csdn.web.service.AdminServiceImpl;

public class AdminListServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

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

		// 获取当前页
		String npage = request.getParameter("nowpage");
		int nowpage = 1;

		// 业务对象
		AdminService aService = new AdminServiceImpl();
		// 获取总记录
		Integer countRecord = aService.findCountRecord();
		// 总页数
		Integer countPage = aService.findCountPage();
		if ("".equals(npage) || npage == null) {
			nowpage = 1;

		} else {
			nowpage = Integer.parseInt(npage);
			if (nowpage < 1) {
				nowpage = 1;
			}
			if (nowpage >= countPage) {
				nowpage = countPage;
			}
		}
		// 当前也得记录信息
		List<Admin> entities = aService.findNowPageInfo(nowpage);

		// 转发
		request.setAttribute("countRecord", countRecord);
		request.setAttribute("countPage", countPage);
		request.setAttribute("nowpage", nowpage);
		request.setAttribute("entities", entities);
		request.getRequestDispatcher("/WEB-INF/listAdmins.jsp").forward(
				request, response);
	}

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

}



 

你可能感兴趣的:(jsp,String,Integer,Path,div,stylesheet)