❶ 实现html页面的分页查询,请问如何用jquery
动态的Ajax分页,代码如下:
<%@pagelanguage="java"contentType="text/html;charset=utf-8"
pageEncoding="utf-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<basehref="<%=basePath%>"/>
<metahttp-equiv="Content-Type"
content="text/html;charset=ISO-8859-1">
<title>Inserttitlehere</title>
<scripttype="text/javascript"src="scripts/jquery-1.5.1.js"></script>
<scripttype="text/javascript">
varlist;//thelistofdata
vartotalPages;//thetotalofpages
varpageSize=5;//eachsizeofpage
varpageIndex=1;//theindexofcurrentpage
$(function(){
send();
});
functionsend(){
$.ajax({
url:"DistrictServlet",
type:"POST",
data:{"function":"list"},
dataType:"json",
success:function(data){
//list=data;
varrecords=data.length;
if(records%pageSize==0){
totalPages=records/pageSize;
}else{
totalPages=Math.round(records/pageSize);
}
$("#pageIndex").html(pageIndex);
$("#totalPages").html(totalPages);
binding(data);
}
});
}
functionchangePage(){
$.ajax({
url:"DistrictServlet",
type:"post",
data:{"function":"list"},
dataType:"json",
success:function(data){
binding(data);
}
});
}
functionbinding(data){
varstart=(pageIndex-1)*pageSize;
varend=pageIndex*pageSize;
varhtml="";
$.each(data,function(index,district){
if(index>=start&&index<end){
//showdata
html+="<tr><td>"+district["id"]+"</td><td>"+district["name"]+"</td></tr>";//.........
}
});
$("table").html(html);
$("#pageIndex").html(pageIndex);
}
functionnextPage(){
pageIndex+=1;
if(pageIndex>totalPages){
pageIndex=totalPages;
return;
}
changePage();
}
functionlastPage(){
pageIndex-=1;
if(pageIndex<1){
pageIndex=1;
return;
}
changePage();
}
functionskipPage(index){
pageIndex=index;
changePage();
}
</script>
</head>
<body>
<div><spanid="pageIndex"></span>/<spanid="totalPages"></span></div>
<div>
<ahref="javascript:lastPage();">last</a>
<ahref="javascript:nextPage();">next</a>
</div>
<divid="list"><table></table></div>
</body>
</html>
❷ 按照thinkphp数据分页写完后前端该怎么写
一、分页方法
/**
 * TODO 基础分页的相同代码封装,使前台的代码更少
 * @param $m 模型,引用传递
 * @param $where 查询条件
 * @param int $pagesize 每页查询条数
 * @return \Think\Page
 */
function getpage(&$m,$where,$pagesize=10){
    $m1=clone $m;//浅复制一个模型
    $count = $m->where($where)->count();//连惯操作后会对join等操作进行重置
    $m=$m1;//为保持在为定的连惯操作,浅复制一个模型
    $p=new Think\Page($count,$pagesize);
    $p->lastSuffix=false;
    $p->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录  每页<b>%LIST_ROW%</b>条  第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
    $p->setConfig('prev','上一页');
    $p->setConfig('next','下一页');
    $p->setConfig('last','末页');
    $p->setConfig('first','首页');
    $p->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
    $p->parameter=I('get.');
    $m->limit($p->firstRow,$p->listRows);
    return $p;
}
getpage方法可以放在TP框架的 Application/Common/Common/function.php,这个文档可以专门放置一些通用的方法,在哪里都可以调用(如:Controller文件,View文件等)。
 
二、调用分页方法
$m=M('procts');
$p=getpage($m,$where,10);
$list=$m->field(true)->where($where)->order('id desc')->select();
$this->list=$list;
$this->page=$p->show();
再是View代码
<div class="pagination">
{$page}
</div>
三、最后就是分页的样式了,这个有些乱,因后台框架网上下载的,样式还没来的及整理,这个样式也可以自己实现,简单的。
.pagination ul {
    display: inline-block;
    margin-bottom: 0;
    margin-left: 0;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.pagination ul li {
  display: inline;
}
.pagination ul li.rows {
    line-height: 30px;
    padding-left: 5px;
}
.pagination ul li.rows b{color: #f00}
.pagination ul li a, .pagination ul li span {
    float: left;
    padding: 4px 12px;
    line-height: 20px;
    text-decoration: none;
    background-color: #fff;
    background: url('../images/bottom_bg.png') 0px 0px;
    border: 1px solid #d3dbde;
    /*border-left-width: 0;*/
    margin-left: 2px;
    color: #08c;
}
.pagination ul li a:hover{
    color: red;
    background: #0088cc;
}
.pagination ul li.first-child a, .pagination ul li.first-child span {
    border-left-width: 1px;
    -webkit-border-bottom-left-radius: 3px;
    border-bottom-left-radius: 3px;
    -webkit-border-top-left-radius: 3px;
    border-top-left-radius: 3px;
    -moz-border-radius-bottomleft: 3px;
    -moz-border-radius-topleft: 3px;
}
.pagination ul .disabled span, .pagination ul .disabled a, .pagination ul .disabled a:hover {
color: #999;
cursor: default;
background-color: transparent;
}
.pagination ul .active a, .pagination ul .active span {
color: #999;
cursor: default;
}
.pagination ul li a:hover, .pagination ul .active a, .pagination ul .active span {
background-color: #f0c040;
}
.pagination ul li.last-child a, .pagination ul li.last-child span {
    -webkit-border-top-right-radius: 3px;
    border-top-right-radius: 3px;
    -webkit-border-bottom-right-radius: 3px;
    border-bottom-right-radius: 3px;
    -moz-border-radius-topright: 3px;
    -moz-border-radius-bottomright: 3px;
}
.pagination ul li.current a{color: #f00 ;font-weight: bold; background: #ddd}
❸ html简单的分页代码怎么写
网页链接
看一下这个吧,现在很少有人手动写分页了,一般都是用插件。或者现在主流的前端框架,都有用户量特别大的前端组件库,用起来很方便。其实这个分页手写js并不难,主要是理清逻辑就可以了,能写但是没必要~如果是比较老的前端框架,必须手写js分页逻辑,追问就行,我给你屡屡
❹ 急求JSP的分页显示的代码和详细步骤
首先要定义四个变量:
int pageSize:每页显示多少条记录
int pageNow:希望显示第几页
int pageCount:一共有多少页
int rowCount:一共有多少条记录
说明:
pageSize是指定的 pageNow是用户选择的
rowCount是计算出来的 该计算式为
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
(技巧:
数据库插入:
insert into 表名(字段1,2,。。。)select 字段1,2,...from 表名
)
查询语句
select top pageSize字段名列表from表名where id not in
(select top pageSize*(pageNow-1)id from 表名)
以我们前面的users表为例,显示第二页,该查询语句就是:
select top 3 * from users where userId not in(select top 3 userId from users)
(select top 3 userId from users):选出这个表的前三条 前面再选三条
<h1>用户信息列表</h1>
<%
//定义四个分页会用到的变量
int pageSize=3;
int pageNow=1;//默认显示第一页
int rowCount=0;//该值从数据库中查询
int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数(pageNow)
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到了pageNow
pageNow=Integer.parseInt(s_pageNow);
}
//查询得到rowCount
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;dataBaseName=System","sa","");
Statement sm=ct.createStatement();
ResultSet rs=sm.exeuteQuery("select count(*) form users ");
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
rs=sm.exeuteQuery("select top "+pageSize
+" * from users where userId not in(select top "
+pageSize*(pageNow-1)+" userId from users) ");
%>
//显示
<table border="1">
<tr><td>用户ID</td><td>用户名字</td><td>密码</td><td>电邮</td><td>级别</td></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getInt(1)%></td><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><%=rs.getInt(5)%></td></tr>
<%}%>
</table>
<%
//上一页
if(pageNow!=1){
out.println("<a href=wel.jsp?pageNow="+(pageNow-1)+">上一页</a>");
}
//显示超链接
for(int i=1;i<=pageCount;i++){
out.println("<a href=wel.jsp?pageNow="+i+">["+i+"]</a>");
}
//下一页
if(pageNow!=pageCount){
out.println("<a href=wel.jsp?pageNow="+(pageNow+1)+">下一页</a>");
}
%>
❺ 求jsp页面实现分页显示数据库查询内容 代码
这个是有条件查询的分页 
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*" %>
<%@page import="entity.Stu"%>
<script>
</script>
<html>
	<title>分页显示(jsp)</title>
	<body>
		<%! 
			int pageSize = 5;//每页显示的记录数 
		    int pageCount = 0;//总页数%>
		<%
			int ageS=0;//开始年龄
			int ageE=0;//结束年龄
			if(request.getParameter("ageS")==null){//判断request里是否有ageS,没有:给ageS赋值并把其放到session里
				ageS=18;
				session.setAttribute("ageS",ageS);
			}else{										//有的话,再对session里的进行判断
				if(!session.getAttribute("ageS").equals(request.getParameter("ageS"))){ //如果session里的值和request里的值不同
					ageS=Integer.parseInt(request.getParameter("ageS").toString());//那么把request里的值赋值给ageS,并放进session里
					session.setAttribute("ageS",request.getParameter("ageS"));
				}else{
					ageS=Integer.parseInt(session.getAttribute("ageS").toString());//否则 ageS直接从session里读取
				}
			}
			if(request.getParameter("ageE")==null){
				ageE=25;
				session.setAttribute("ageE",ageE);
			}else{
				if(!session.getAttribute("ageE").equals(request.getParameter("ageE"))){
					ageE=Integer.parseInt(request.getParameter("ageE").toString());
					session.setAttribute("ageE",request.getParameter("ageE"));
				}else{
					ageE=Integer.parseInt(session.getAttribute("ageE").toString());
				}
			}
			Connection conn = null;
			String driver = "oracle.jdbc.driver.OracleDriver";
			String url = "jdbc:oracle:thin:@localhost:1521:orcl";
			try {
				Class.forName(driver);
				conn = DriverManager.getConnection(url, "system", "zhu");
				PreparedStatement st=conn.prepareStatement("select * from stu where age>="+ageS+" and age<= "+ageE+" order by sid",
				ResultSet.TYPE_SCROLL_SENSITIVE,
				ResultSet.CONCUR_READ_ONLY);//可滚动查询数据的结果集
				ResultSet rs = st.executeQuery();
				
				rs.last();//让游标到表中的最后一行
				int rowCount = rs.getRow();//获取记录总数
				//out.print("记录总数为 :"+rowCount);
				//总也数的计算公式
				pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize)
						: (rowCount / pageSize + 1);
				int showPage = 1;//当前页
		%>
		<%
			//取得用户指定的页
				String goTOPage = request.getParameter("showPage");
				if (goTOPage == null) {
					goTOPage = "1";
				}
				try {
					showPage = Integer.parseInt(goTOPage);
				} catch (NumberFormatException e) {
					showPage = 1;
				}
				//当页面小于等于第一页。按第一页算 如果大于等于总页数。按最后一页算
				if (showPage <= 1) {
					showPage = 1;
				} else if (showPage >= pageCount) {
					showPage = pageCount;
				}
				//游标的位置(当前页-1)×每页显示的记录数+1
				int posion = (showPage - 1) * pageSize + 1;
				//设置游标的位置
				rs.absolute(posion);
				
		%>
		<form action="" method="get">    年龄段:<input type="text" value="<%=ageS %>"  name="ageS"/>——<input type="text" value="<%=ageE %>"  name="ageE"/> 
			<input type="submit" value="查询"/>
		
		<table border="1" cellpadding="0" cellspacing="0">
			<tr>
				<td>序号</td>
				<td>
					编号
				</td>
				<td>
					姓名
				</td>
				<td>
					年龄
				</td>
			</tr>
			<%
				int num=showPage*pageSize-4;
				int i = 0;
					//循环显示表中的数据pageSize(每页显示的记录)
					//rs.isAfterLase()游标是否在最后一行之后 说明后面已经没有记录
					while (i < pageSize && !rs.isAfterLast()) {
			%>
			<tr>
				<td>
					<%=num %>
				</td>
				<td>
					<%=rs.getInt("sid") %>
				</td>
				<td>
					<%=rs.getString("sname") %>
				</td>
				<td><%=rs.getInt("age") %>
				</td>
			</tr>
			<%
				rs.next();
						i++;
						num++;
					}
			%>
		</table>
			<table width="1000">
				<tr style=" vertical-align:middle;">
					<td>
						<a href="page1.jsp?ageS=<%=ageS %>&ageE=<%=ageE %>&showPage=1">首页</a>
					</td>
					
					<td>
						<%
							if (showPage > 1) {
						%>
						<a href="page1.jsp?ageS=<%=ageS %>&ageE=<%=ageE %>&showPage=<%=showPage - 1%>">上一页</a>
						<%
							}else{
						%>
							上一页
						<%} %>
					</td>
					<td>
						<%
							if (showPage < pageCount) {
						%>
						<a href="page1.jsp?ageS=<%=ageS %>&ageE=<%=ageE %>&showPage=<%=showPage + 1%>">下一页</a>
						<%
							}else{
						%>
							下一页
						<%} %>
					</td>
					<td>
						<a href="page1.jsp?ageS=<%=ageS %>&ageE=<%=ageE %>&showPage=<%=pageCount%>">尾页</a>
					</td>
					<td>
						共<%=pageCount%>页
					</td>
					<td>
						第<%=showPage%>页
					</td>
				</tr>
			</table>
		</form>
		<%
			conn.close();
			} catch (ClassNotFoundException e1) {
				out.print(e1.getMessage());
			} catch (SQLException e2) {
				out.print(e2.getMessage());
			}
		%>
	</body>
</html>
❻ 在同一页面中如何实现查询并分页显示结果
建立access的数据库news,还有表news,表的字段(id,title),id唯一,输入数据保存,用下面代码可查询,可分页 
-----------------------下面保存为search.asp-------------------------- 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>文件</title> 
</head> 
<body bgcolor="#ffffff"> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<script> 
function btn_ck_bh_Click() 
{ 
var cx = document.form1.cxsj.value; 
form1.action ="search.asp?cx="+cx; 
} 
</script> 
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all"> 
<tr> 
<td width="778" align="center" colspan="7"> 
<form method="POST" name="form1" action=search.asp> 
<p>输入搜索内容:<input type="text" name="cxsj" size="20"><input type="submit" value="提交" name="B1" LANGUAGE="javascript" onclick="btn_ck_bh_Click()"> 
<input type="reset" value="重写" name="B2"></p> 
</form> 
</td> 
</tr> 
</table> 
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all"> 
<tr> 
<td width="8%" align="center"><strong><font color="#0080C0">ID 号</font></strong></td> 
<td width="58%" align="center"><strong><font color="#0080C0">标 题</font></strong></td> 
<td width="8%" align="center"><strong><font color="#0080C0">修 改</font></strong></td> 
<td width="8%" align="center"><strong><font color="#0080C0">删 除</font></strong></td> 
</tr> 
<% 
'数据库查询 
'获得搜索内容 
cx = request("cx") 
dim pageCount 
'把page转换成整数 
page = cint(request("page")) 
set conn=server.createobject("adodb.connection")' 
set rs=server.createobject("adodb.recordset") 
conn.open "DBQ=" & server.mappath("./news.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
' 获取产品的名字记录集(从 news表中) 
if cx <> "" then 
sql = "select * from news where title like '%"&cx& "%' order by id desc" 
else 
sql ="select * from news order by id desc" 
end if 
rs.open sql,conn,3,3 
'如果没有数据记录 
if rs.bof then 
errmsg=errmsg+"<br>"+"<li>"+keyword+"没有记录,请返回!!" 
response.write errmsg 
response.end 
end if 
' 设置记录集在每页的总行数,也就是 PageSize属性 
RS.PageSize=40 
'把rs.pageCount转换成整数和page才能作比较 
pageCount = cint(rs.pageCount) 
' 设置当前的页号( AbsolutePage属性) 
if page = 0 then 
page =1 
end if 
RS.AbsolutePage = page 
x=1 
' 显示当前页中的所有记录( PageSize中设置的行数) 
WHILE NOT RS.EOF AND NumRows<RS.PageSize 
%> 
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''"> 
<td width="8%"><p align="center"><%=rs("id")%></td> 
<td width="58%"><a href="view.asp?id=<%=rs("id")%>" target="_blank"><%=rs("title")%></a></td> 
<td width="8%" align="center"><a href="edit.asp?id="<%=rs("id")%>>修 改</a></td> 
<td width="8%" align="center"><a href="delet.asp?id="<%=rs("id")%>>删 除</a></td> 
</tr> 
<%RS.MoveNext 
NumRows=NumRows+1 
WEND%> 
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''"> 
<td width="105%" align="center" colspan="6"> </td> </tr> 
<tr> 
<td width="105%" align="center" colspan="6"> 
<p align="center"><FONT color=#333333>共<%=PageCount%>页 第<%=page%>页★ 
<%if page=1 then%>首页<%end if%> 
<%if page>1 then%> 
<A HREF="search.asp?page=1&cx=<%=cx%>"> 首页</A> 
<%end if%>★ 
<%if page>1 then%><A HREF="search.asp?page=<%=page-1%>&cx=<%=cx%>"><%end if%>上一页</a> 
<% 
dim pagewhere 
dim p 
p = 1 
'把pagewhere转换成整数 
'pagewhere = cint(request("pagewhere")) 
pagewhere = pageCount 
if pagewhere>0 then 
for p=1 to pagewhere 
if p <> page then%> 
<A HREF="search.asp?page=<%=p%>&cx=<%=cx%>"><%=p%></a> 
<%end if 
if p =page then%> 
<%=p%> 
<% end if 
next 
end if%> 
<%if page < PageCount then%> 
<A HREF="search.asp?page=<%=page+1%>&cx=<%=cx%>"> 
<%end if %>下一页</A>★ 
<%if page=PageCount then%>尾页 
<%end if%> 
<%if page<PageCount then%> 
<A HREF="search.asp?page=<%=PageCount%>&cx=<%=cx%>"> 尾页</A> 
<%end if%> 
</p></FONT></td> </tr> <tr> 
<td width="105%" align="center" colspan="6">搜索内容:<%=cx%></td> 
</tr> 
</table></center></div> 
</body></html> 
<% 
rs.close 
Set rs=nothing 
conn.close 
set conn=nothing 
%>
❼ 前端一下获取所有数据怎么实现分页
grid的分页功能本身就是对数据库数据分页后的一个数据显示,并可以执行翻页查询其他页的信息。全部信息则只需要将limit参数设置为数据总条数,pagesize也设置为数据行数。grid中不设置分页组件是可以直接显示全部信息,url中不设置limit和start参数。注:数据量太多时不宜全部显示
❽ 前端开发 需要根据把后台数据列表 分页显示
搭建项目分页
1.jsp页面
<tr>
<td bgcolor="#00ffff" colspan="10" align="center">
第${pager.currentPage}页
每页${pager.pageSize} 条记录
共${pager.totalPages}页
共${pager.totalRows} 条
<a href="servlet/UserServlet?num=1&page=1" >首页</a>
<a href="servlet/UserServlet?num=1&page=${pager.currentPage-1}">上一页</a>
<a href="servlet/UserServlet?num=1&page=${pager.currentPage+1}">下一页</a>
<a href="servlet/UserServlet?num=1&page=${pager.totalPages}">末页</a>
</td>
</tr>
2.拼接sql语句
SELECT * FROM USERS LEFT JOIN DEPT ON USERDEPT=DEPTNUM
SELECT * FROM(SELECT A.*, ROWNUM RN FROM (SELECT * FROM student) A WHERE ROWNUM <=15)WHERE RN >=11 ORDER BY ENTERDATE
分页sql:SELECT * FROM(SELECT A.*, ROWNUM RN FROM (SELECT * FROM USERS LEFT JOIN DEPT ON USERDEPT=DEPTNUM) A WHERE ROWNUM <=15)WHERE RN >=11 ORDER BY ENTERDATE
3.分页工具类导入到common包:Pager.java
在servlet调用:第一个条件:总条数 第二个条件:当前页数
String page = request.getParameter("page");
//分页调用开始--------------------------------
Pager pager = new Pager();
int totalRows = userService.getCountRows();
pager.setTotalRows(totalRows);
if(null != page){
pager.setCurrentPage(Integer.parseInt(page));
}else{
pager.setCurrentPage(1);
}
request.setAttribute("pager", pager);//给页面分页赋值
4.把pager工具类传递到,拼接执行动态分页sql语句
开始条数:pager.getStartRow()
结束条:pager.getCurrentPage()*pager.getPageSize()
String sql="SELECT * FROM(SELECT A.*, ROWNUM RN FROM (SELECT * FROM USERS LEFT JOIN DEPT ON USERDEPT=DEPTNUM) A WHERE ROWNUM <="+pager.getCurrentPage() *pager.getPageSize()+")WHERE RN >="+pager.getStartRow();//分页sql 1-3条
分页根本条件:
private int totalRows; //总行数
private int pageSize = 5; //每页显示的行数
private int currentPage=1; //当前页号
private int totalPages; //总页数
private int startRow; //当前页在数据库中的起始行
private int endRow; //数据库执行sql的结束行
totalPages算法:
if(totalRows<=pageSize){
totalPages=1;
}else{
totalPages=(totalRows+pageSize-1)/pageSize;
}
startRow; 算法:
startRow=(currentPage-1) * pageSize+1;
endRow; endRow=currentPage* pageSize;
❾ jsp 如何将查询结果实现分页,最好简单易懂…
jsp中分页最快捷的办法是用分页组件:
分页组件代码使用taglib实现的:
<%@ tag language="java" pageEncoding="UTF-8"%>  
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>  
<%@ attribute name="curIndex" type="java.lang.Long" required="true"%>  
<%@ attribute name="pageSize" type="java.lang.Long" required="true"%>  
<%@ attribute name="pagerRange" type="java.lang.Long" required="true"%>  
<%@ attribute name="totalPage" type="java.lang.Long" required="true"%>  
<%@ attribute name="formId" type="java.lang.String" required="true"%>  
<%  
    long begin = Math.max(1, curIndex - pagerRange/2);  
    long end = Math.min(begin + (pagerRange-1),totalPage);  
      
    request.setAttribute("p_begin", begin);  
    request.setAttribute("p_end", end);  
%>  
    <table class="pager">  
    <tr>  
         <% if (curIndex!=1){%>  
                <td><a href="javascript:gotoPage(1)">首页</a></td>  
                <td><a href="javascript:gotoPage(<%=curIndex-1%>)">上一页</a></td>  
         <%}else{%>  
                <td class="disabled"><a href="#">首页</a></td>  
                <td class="disabled"><a href="#">上一页</a></td>  
         <%}%>  
   
        <c:forEach var="i" begin="${p_begin}" end="${p_end}">  
            <c:choose>  
                <c:when test="${i == curIndex}">  
                    <td class="active"><a href="#">${i}</a></td>  
                </c:when>  
                <c:otherwise>  
                    <td><a href="javascript:gotoPage(${i})">${i}</a></td>  
                </c:otherwise>  
            </c:choose>  
        </c:forEach>  
  
         <% if (curIndex!=totalPage){%>  
                <td><a href="#">下一页</a></td>  
                <td><a href="#">末页</a></td>  
         <%}else{%>  
                <td class="disabled"><a href="javascript:gotoPage(<%=curIndex+1%>)">下一页</a></td>  
                <td class="disabled"><a href="javascript:gotoPage(<%=totalPage%>)">末页</a></td>  
         <%}%>  
         <td><a>共${totalPage}页</a></td>  
         <td class="input_li">跳转到:<input type="text" id="p_pageIndex" size="2" value="<c:out value="${pageIndex}"/>"/>页 <input type="button" id="gotoBtn" onclick="gotoPageByBtn()" value="GO"/></td>  
         <td class="input_li"> 每页:  
         <select id="p_pageSizeSelect" onchange="gotoPage(<%=curIndex%>)">  
            <option value="10" <c:if test="${pageSize==10}">selected</c:if>>10条</option>  
            <option value="20" <c:if test="${pageSize==20}">selected</c:if>>20条</option>  
            <option value="50" <c:if test="${pageSize==50}">selected</c:if>>50条</option>  
         </select>  
         </td>  
    </tr>  
    </table>  
jsp中使用方法:
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags"%>
<head>
<style><!--分页样式-->
.pager { font: 12px Arial, Helvetica, sans-serif;}
.pager a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px;line-height:30px;vertical-align:middle;}
.pager .active a{color:red;border:none;}
.pager a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.pager a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
.pager .input_li{padding: 1px 6px;}
</style>
<script><!--分页跳转脚本-->
function gotoPage(pageIndex){
	var queryForm = document.getElementById("queryForm");
	var action = queryForm.action;
	var pageSize = document.getElementById("p_pageSizeSelect").value;
	action += "?pageIndex=" + pageIndex + "&pageSize=" + pageSize;
	//alert(action);
	queryForm.action = action;
	queryForm.submit();
}
function gotoPageByBtn(){
	var pageIndex = document.getElementById("p_pageIndex").value;
	var pageIndexInt = parseInt(pageIndex);
	var totalPage = ${totalPage};
	
	if(pageIndexInt>0 && pageIndexInt<totalPage){
		gotoPage(pageIndex);
	}
	else{
		alert("输入页数超出范围!");
	}
}
</script>
</head>
<body>
<form id="queryForm" action="${basePath}/log/list" method="post">
<table>
	<tr>
	<td>用户名:</td>
	<td><input type="text" name="userName" value="<c:out value="${userName}"/>"/> </td>
	<td><input type="submit" text="查询"/></td>
	</tr>
</table>
</form>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
<table class="border">
	<thead>
		<tr>
			<th width="100">用户名称</th>
			<th width="500">操作内容</th>
			<th width="200">操作时间</th>
		</tr>
	</thead>
	<tbody>
	<c:forEach items="${logList}" var="log">
		<tr>
			<td>${log.userName}</td>
			<td>${log.result}</td>
			<td>
			<fmt:formatDate value="${log.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</td>
		</tr>
	</c:forEach>
	</tbody>
</table>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
</body>
❿ java的jsp如何分页显示查询结果呢
//分页类
publicclassPager{
privateintpageNow=1;//
privateintpageSize=7;//
privateinttotalPage;//
privateinttotalSize;//
publicPager(intpageNow,inttotalSize){
this.pageNow=pageNow;
this.totalSize=totalSize;
}
publicintgetPageNow(){
returnpageNow;
}
publicvoidsetPageNow(intpageNow){
this.pageNow=pageNow;
}
publicintgetPageSize(){
returnpageSize;
}
publicvoidsetPageSize(intpageSize){
this.pageSize=pageSize;
}
publicintgetTotalPage(){
totalPage=getTotalSize()/getPageSize();
if(totalSize%pageSize!=0)
totalPage++;
returntotalPage;
}
publicvoidsetTotalPage(inttotalPage){
this.totalPage=totalPage;
}
publicintgetTotalSize(){
returntotalSize;
}
publicvoidsetTotalSize(inttotalSize){
this.totalSize=totalSize;
}
publicbooleanisHasFirst(){
if(pageNow==1)
returnfalse;
else
returntrue;
}
publicvoidsetHasFirst(booleanhasFirst){
}
publicbooleanisHasPre(){
if(this.isHasFirst())
returntrue;
else
returnfalse;
}
publicvoidsetHasPre(booleanhasPre){
}
publicbooleanisHasNext(){
if(isHasLast())
returntrue;
else
returnfalse;
}
publicvoidsetHasNext(booleanhasNext){
}
publicbooleanisHasLast(){
if(pageNow==this.getTotalPage())
returnfalse;
else
returntrue;
}
publicvoidsetHasLast(booleanhasLast){
}
}
//service层
publicclassPageService{
@SuppressWarnings("unchecked")
publicList<?>list(intpageNow,intpageSize,Stringhql){
Sessionsession=HibernateSessionFactory.getSession();
Transactiontx=session.beginTransaction();
List<Object>objects;
Queryquery=session.createQuery(hql);
query.setFirstResult(pageSize*(pageNow-1));
query.setMaxResults(pageSize);
objects=query.list();
tx.commit();
returnobjects;
}
}
//在action中调用
publicStringlistUser(){
Stringhql="fromUserinfou";
if(ps.list(pageNow,pageSize,hql)!=null){
userinfos=(List<Userinfo>)ps.list(pageNow,pageSize,hql);
Map<String,Object>request=(Map<String,Object>)ActionContext
.getContext().get("request");
Pagerpage=newPager(this.getPageNow(),us.getUserSize());
request.put("userinfos",userinfos);
request.put("page",page);
returnAction.SUCCESS;
}else{
returnAction.LOGIN;
}
}
//jsp中
<body>
<tablewidth="832"border="0"cellpadding="0"cellspacing="0"id="listBook">
<trbgcolor="#E7E7E9">
<tdwidth="5%"height="40"> </td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"><divalign="center"class="STYLE10">邮箱</div></td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"class="STYLE1"><divalign="center"class="STYLE10">密码</div></td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"class="STYLE1"><divalign="center"class="STYLE10">权限</div></td>
<tdwidth="8%"bgcolor="#E7E7E9"><spanclass="STYLE8"></span></td>
<tdwidth="8%"bgcolor="#E7E7E9"><spanclass="STYLE8"></span></td>
</tr>
<s:iteratorvalue="#request.userinfos"id="oneUser">
<tr>
<tdheight="50">
<divalign="center">
<inputtype="checkbox"name="checkbox"value="checkbox"/>
</div></td>
<tdwidth="5%"></td>
<tdwidth="23%"class="STYLE4"><s:property
value="#oneUser.email"/></td>
<tdwidth="5%"class="STYLE4"></td>
<tdwidth="23%"><spanclass="STYLE4"><s:property
value="#oneUser.password"/></span></td>
<tdwidth="5%"class="STYLE4"></td>
<tdwidth="23%"><spanclass="STYLE4">
<s:iftest="#oneUser.power==1">
普通用户
</s:if>
<s:else>
管理员
</s:else>
</span></td>
<td><divalign="right"class="STYLE1"><ahref='deleteUser?userid=<s:propertyvalue="#oneUser.id"/>'class="STYLE5">删除|</a></div></td>
<tdclass="STYLE1"><ahref='lookUser?userid=<s:propertyvalue="#oneUser.id"/>&pageNow=<s:propertyvalue="#request.page.pageNow"/>'target="_self"class="STYLE5">修改</a></td>
</tr>
</s:iterator>
<tr>
<tdcolspan="9"><tablewidth="832"border="0"cellspacing="0"bgcolor="#E7E7E9">
<s:setname="page"value="#request.page"></s:set>
<tr>
<tdwidth="70%"> </td>
<s:iftest="#page.isHasPre()">
<tdwidth="10%"><ahref='listUser?pageNow=<s:propertyvalue="#page.pageNow-1"/>'target="_self"class="STYLE3">上一页</a></td>
</s:if>
<s:else>
<tdwidth="10%"><ahref="listUser?pageNow=1"target="_self"class="STYLE3">上一页</a></td>
</s:else>
<s:iftest="#page.isHasNext()">
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.pageNow+1"/>"target="_self"class="STYLE3">下一页</a></td>
</s:if>
<s:else>
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.totalPage"/>"target="_self"class="STYLE3">下一页</a></td>
</s:else>
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.totalPage"/>"target="_self"class="STYLE3">尾页</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>这是采用struts2+hibernate 做的,你可以参考一下
