Javabean包
=====================================================================================
package cn.csdn.domain;
import java.util.List;
public class Page {
private int nowpage;// 当前页
private int countrecord;// 总记录数
private int countpage;// 总页数
public static final int PAGESIZE = 5;// 每页显示的记录数
private int startindex;// 开始的索引值
private int endindex;// 结束的索引值
private List allentities;
private int listPageSize;
public int getListPageSize() {
return listPageSize;
}
public void setListPageSize(int listPage) {
this.listPageSize = listPage ;
}
public Page() {
}
public int getNowpage() {
return nowpage;
}
public void setNowpage(int nowpage) {
this.nowpage = nowpage;
}
public int getCountrecord() {
return countrecord;
}
public void setCountrecord(int countrecord) {
this.countrecord = countrecord;
}
public int getCountpage() {
return countpage;
}
public void setCountpage(int countpage) {
this.countpage = countpage;
}
public int getStartindex() {
if (nowpage > this.getListPageSize()/2) {
if (countpage - nowpage > this.getListPageSize()/2) {
startindex = nowpage - this.getListPageSize()/2;
} else {
startindex = countpage -this.getListPageSize();
}
}
return startindex;
}
public void setStartindex(int startindex) {
this.startindex = startindex;
}
public int getEndindex() {
if ((nowpage + this.getListPageSize()/2)>countpage) {
return endindex = countpage;
} else {
return endindex = endindex + nowpage - 1;
}
}
public void setEndindex(int endindex) {
this.endindex = endindex;
}
public List getAllentities() {
return allentities;
}
public void setAllentities(List allentities) {
this.allentities = allentities;
}
}
===============================================================================================
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.service.StudentServiceImpl;
import cn.csdn.domain.Page;
import cn.csdn.domain.Student;
public class ListStusServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//1.设置编码
req.setCharacterEncoding("utf8");
//2.获取当前页
Page stupage = new Page();
int nowpage=1;
String npage = req.getParameter("nowPage");
if(npage!=null){
nowpage = Integer.valueOf(npage);
}
StudentServiceImpl ssi = new StudentServiceImpl();
stupage.setCountpage(ssi.getCountPage());
stupage.setNowpage(nowpage);
int pageListSize=10;
stupage.setStartindex(1);
stupage.setListPageSize(pageListSize);
if(pageListSize%2==0){
stupage.setEndindex(stupage.getListPageSize()/2);
}else{
stupage.setEndindex(stupage.getListPageSize()/2+1);
}
stupage.setCountpage(ssi.getCountPage());
List<Student> allentities = ssi.getNowPageInfo(nowpage);
stupage.setAllentities(allentities);
stupage.setCountrecord(ssi.getCountRecord());
req.setAttribute("stupage", stupage);
req.getRequestDispatcher("liststs.jsp").forward(req, resp);
}
}
=========================================================================================
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>全部学生</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">
<h1>
显示所有的学员信息
</h1>
<table border="1px" cellpadding="0" cellspacing="0" width="600"
height="400">
<caption>
学员信息
</caption>
<tr>
<th>
全选
</th>
<th>
序列
</th>
<th>
姓名
</th>
<th>
年龄
</th>
<th>
邮箱
</th>
<th>
操作
</th>
</tr>
<c:forEach items="${stupage.allentities}" var="student">
<tr>
<td>
<input type="checkbox" name="chk" />
</td>
<td>
${student.id}
</td>
<td>
${student.name}
</td>
<td>
${student.age}
</td>
<td>
${student.email}
</td>
<td>
编辑|删除
</td>
</tr>
</c:forEach>
</table>
<div>
<c:if test="${stupage.nowpage!=1}">
<span><a href="./StudentList.do?nowPage=${stupage.nowpage-1}">上一页</a>
</span>
</c:if>
<c:forEach begin="${stupage.startindex}" end="${stupage.endindex}" var="indexPage">
<a href="./StudentList.do?nowPage=${indexPage}"
<c:if test="${stupage.nowpage==indexPage}"> style="color: red" </c:if>><span>[
${indexPage} ]</span> </a>
</c:forEach>
<c:if test="${stupage.nowpage+1<=stupage.countpage}">
<span><a href="./StudentList.do?nowPage=${stupage.nowpage+1}">下一页</a>
</span>
</c:if>
</div>
</div>
</body>
</html>
分享到:
相关推荐
超强php分页打包 通用分页 万能分页 ajax分页 google分页
会形成多种不一样的分页页面,风格各异,她自带的DEMO就有七种左右的分页风格,包括Google的分页风格。而需要订制自已的风格的分页页 面也非常简单。 分页方式有两种: 第一种是页面分页,适合查询结果不大情况 ...
PHP通用分页类(仿Google样式)。本代码是用于分页用的,只需提供记录总数与每页显示数两个参数,无需指定URL,链接由程序生成。方便用于检索结果分页,表单采用GET方法提交,可保证在诸如查询之,删除之类的操作时,...
类似淘宝谷歌的通用分页.支持oracle mssql2000 mysql,需要把struts1的jar文件 自己放进去.太大了就不传
非常好用的分页类,很容易定制各种风格,可以与网上流行的 《24款超实用的Web 2.0风格翻页页码css代码》 完美无缝连接。你所做的,就是改个div的名字而已。另外懂点儿CSS的朋友甚至可以轻松实现仿Google的翻页样式。
jh-plugins是一项基于JSTL的自定义标签(插件)库,致力于打造一处实现、任何项目通用的开源项目。 jh-plugins已实现标签库:分页 jh-plugins特点:高效、轻巧、简单、适用(可融合与任何B/S架构的java项目) jh-...
PHP通用分页类。本代码是用于分页用的,稍做修改可用于各种程序。使用方式请参考本人文章。
关于分页存储过程的资料很多,我就不多说了,Google一下你就知道了。也发一个存储过程,方便大家。性能还算可以吧,支持多表查询,多字段排序,但是必须主键唯一,要是哪位兄弟有支持主键重复的,请告之。 思路说明...
不过由于小弟资历浅薄,也没心思看,主要是strut2的标签本来我就觉得不大习惯,另外上个月接触了freemarker后,实在是用的爽死了,为什么不用freemarker的macro指令写个通用的分页呢?马上想到模仿TX的...
在google中搜索“分页存储过程”会出来好多结果,是大家常用的分页存储过程,今天我却要说它是有漏洞的,而且漏洞无法通过修改存储过程进行补救,如果你觉得我错了,请读下去也许你会改变看法。 通常大家都会认为...
1.主题,Asp.net环境下,通用的数据分页(包括Oracle,SqlServer,DB2…) 很久以前,就想做一个通用点的数据分页组件,但苦于一直没有充足的时间,所以迟迟没有实现(当然,主要是因为有一定的难度,要处理视图状态,回传事件,自...
Protobuf & json | 数据序列化 | [https://github.com/google/protobuf](https://github.com/google/protobuf) Jenkins | 持续集成工具 | [https://jenkins.io/index.html](https://jenkins.io/index.html) Maven | ...
通过将搜索对象传递给通用DAO和通用DAO的搜索方法,可以使用此功能。 搜索对象提供了灵活的搜索选项: 使用标准运算符(=,!=,>,<,> =,<=,LIKE,IN,IS NULL和IS EMPTY)对属性进行过滤。 使用...
JSF 模块为 jsf 提供支持以利用它,它已被通用化以便它可以与任何其他表示技术一起使用。 查看演示项目presenter-demo Java文档? 从主界面 IDataConroller: 此接口是与此 CRUD 层交互以进行各种操作的中心点。 ...
全局,通用和个性化样式; 导入Google字体; 分页; 计算预计的阅读时间; 使用getStaticProps和getStaticPaths方法生成静态页面; 使用date-fns格式化日期; 使用带有react-icons ; 带fetch HTTP请求; 第2...
一个基于SSM的通用后台管理系统,可以快速接入到自己系统中,包含账号,角色,服务器管理,日志等相关功能,可以简化项目开发难度 默认用户名 root 密码root 优化: 此版本不再使用前版本在dao层创建session方法来进行数据...
jTPS - jQuery 数据表插件 数据表上分页的动画滚动。 支持列的升序和降序“自然排序”。 支持从传统 HTML 和/或模板驱动的 HTML 表格附加到通用预建表格。
{maccms:link_map_google} Google SiteMap链接 {maccms:count_vod_all} 视频数据总量 {maccms:count_vod_day} 视频当天更新数据量 {maccms:count_art_all} 文章数据总量 {maccms:count_art_day} 文章当天更新数据量 ...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...