求教jsp分页显示的问题,如何循环并分页取得参数?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求教jsp分页显示的问题,如何循环并分页取得参数?相关的知识,希望对你有一定的参考价值。

Page page = PageUtil.createPage(3, esql.findAllCount(), currentPage);//创建页面为:每页显示3个、取得总显示数、当前页。
List<Employee> employees = esql.findEmployees(page);//取得员工的集合类

员工属性有userName、employeeNo、roleId
据此,如何分页显示员工的信息?

这个是一个可用的分页代码,如何调用就不说了吧,但是在用之前要先指明ResultSet的值

import java.sql.ResultSet;
public class rsFenYe
ResultSet rs=null; //要分页处理的记录数
int currentPage=1; //当前页码
int pageSize=10; //每页记录的条数,默认为10
/**
* 得到分页字串,并把记录指针移到当前页的第一条记录的前面的位置
* 输入:返回的JSP页面,refName 数组为超链接中继 currentPage 之后的参数名,refValue为对应值
* 输出:字符串“共2页,当前第1页 下一页 末页”
*/
public String earn_fenye_string(String returnJSP)
String returnString=new String("");
if(rs==null)
return returnString;

int pageCount=0; //总页数
int rowCount=0; //rs的总记录条数
if(pageSize<=0) //每页记录条数不正确
return returnString;


try
//------得到记录总条数--------
rs.last();
rowCount=rs.getRow();
rs.beforeFirst();

//------记录指针移位----------
int RecordPosition=(currentPage-1)*pageSize;
if(RecordPosition==0)
rs.beforeFirst();
else
rs.absolute(RecordPosition);

catch(Exception e)
System.out.println(e);
return returnString;


//-------得到总页数-----
if(rowCount%pageSize==0)
pageCount=rowCount/pageSize;
else
pageCount=rowCount/pageSize+1;


//-------得到返回字符串--------
returnString="共"+pageCount+"页,当前第"+currentPage+"页  ";
if(currentPage!=1 && pageCount!=0) //不是首页且总页数不为0
returnString=returnString+"<a href='"+returnJSP+"?currentPage=1";
returnString=returnString+"'>首页</a> ";

returnString=returnString+"<a href='"+returnJSP+"?currentPage="+(currentPage-1);
returnString=returnString+"'>上一页</a> ";


if(currentPage!=pageCount&&pageCount!=0) //不是末页且总页数不等于0
returnString=returnString+"<a href='"+returnJSP+"?currentPage="+(currentPage+1);
returnString=returnString+"'>下一页</a> ";

returnString=returnString+"<a href='"+returnJSP+"?currentPage="+pageCount;
returnString=returnString+"'>末页</a> ";


return returnString;


public ResultSet getRs()
return rs;


public void setRs(ResultSet rs)
this.rs = rs;


public int getCurrentPage()
return currentPage;


public void setCurrentPage(int currentPage)
this.currentPage = currentPage;


public int getPageSize()
return pageSize;

public void setPageSize(int pageSize)
this.pageSize = pageSize;

参考技术A 写一个分页类,在servlet调用里面的方法取数据并传到jsp页面
分页类
package Tool;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import com.sun.crypto.provider.RSACipher;
import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;

public class Pagination2
static int renum;//数据库中所有数据
static int pagenow;//当前页
static int pagesize;//每页显示数据数
static int pagenum;//总页数
public static int Renum(List list)
int i=0;
for(;i<list.size();i++);
renum=i;
return renum;

public static int Pagenum(int pagesize,int renum)
pagenum=renum%pagesize==0?renum/pagesize:renum/pagesize+1;
return pagenum;

public static String Page(int pagenow,int pagenum)
int i;
String page="<script type='text/javascript'> function jump()var jump=document.getElementById('jump');alert(jump.value);if(jump.value>0&&jump.value<="+pagenum+")location.href='test?pagenow='+jump.valueelsealert('请输入正确的页数')</script><table> <tr> <td><input type='text' name='jump' id='jump'><input type='button' value='跳转' onclick='jump()'>当前页 "+pagenow+"/总页数"+pagenum+"";
if(pagenow>1)
page=page+" <a href='test?pagenow="+(pagenow-1)+"'>上一页</a>";

String page2="";
if(pagenow<=pagenum-2)
int j=pagenow+3;
i=pagenow;
do
page2=page2+"  <a href='test?pagenow="+i+"'>"+i+"</a>";
i++;
while(i<j&&i<=pagenum);
else
for(i=pagenum-2;i<=pagenum;i++)
page2=page2+"  <a href='test?pagenow="+i+"'>"+i+"</a>";


page=page+page2;
if(pagenow<pagenum)
page=page+" <a href='test?pagenow="+(pagenow+1)+"'>下一页</a></td></tr></table>";

return page;

public static List dateList(int pagenow,List list,int pagesize)
List list2=new ArrayList();
for(int i=(pagenow-1)*pagesize;i<pagenow*pagesize&&i<list.size();i++)
list2.add(list.get(i));

return list2;


jsp页面
<c:forEach items="$list" var="item" >
<tr>
<td><c:out value="$item.参数 "></c:out></td>
</tr>
</c:forEach>
<%=page2 %>
参考技术B for(int i=currentPage*3;i<(currentPage+1)*3;i++)
Employee employee = employees .get(i);
//显示
//................

mysql存储过程嵌套循环并分页处理数据

业务背景:公司存证产品升级,随着数据量的增加,存证产品线按业务分表,导致以往的存证关联数据需要做数据同步更新。版本发布前,通过当前存储过程解决数据升级问题。

##创建存证文档关联情况下更新所用存储过程
CREATE PROCEDURE evi_doc_refs_eid_deal() begin declare pageNum int default 0; declare totalSize int default 0; declare pageSize int default 5; declare totalPage int DEFAULT 0; declare startIndex int default 0; select count(*) into totalSize from osv_service_evidence where type != 11 and type !=12 and type !=50 ; set totalPage = totalSize/pageSize; while ( pageNum<totalPage-1) do #对分页的起始下标计算,以便分页查询时使用 set startIndex = pageNum *pageSize; #开启事务  START TRANSACTION; #嵌套内部分页查询,通过游标处理分页查询结果记录 begin #声明变量 declare eviId varchar(50); declare evidenceEid varchar(50); declare done int default 0; declare mark varchar(2); declare eid_value varchar(50); declare type_value int default 0; declare eid_mark varchar(50);      declare num int DEFAULT 0;     #定义分页查询结果的游标 declare i_cur cursor for select id from osv_service_evidence where type !=11 and type !=12 and type !=50 limit startIndex,pageSize; declare continue handler for sqlstate 09000 set done = 1; open i_cur; fetch next from i_cur into eviId; WHILE (done = 0 ) do #判断每页中处理数据的下标index set num = num+1; select type into type_value from osv_service_evidence where id = eviId; select e.eid into eid_value from osv_service_evidence e where id = eviId; if(0 =type_value|null = eid_value) then fetch next from i_cur into eviId; end if;       #数据处理 if type_value =40 then set mark = O; set eid_mark=concat(mark,eid_value);update evi_doc_refs set docEid = eid_mark where docEviId = eviId; elseif type_value =11 then set mark = S; set eid_mark=concat(mark,eid_value);update evi_doc_refs set docEid = eid_mark where docEviId = eviId;set done = 0; end if;      #如果当前页处理的数据已达页记录数值,通过done退出内部循环,进入外部循环      IF num = pageSize THEN set done = 1;      #否则继续当前循环       ELSEIF num !=pageSize THEN set done =0;       fetch next from i_cur into eviId;       END IF; END WHILE;     #关闭游标 close i_cur; end ; COMMIT;   #更新下一次处理的页码,+1 set pageNum = pageNum+1; end while; END;


call evi_doc_refs_eid_deal();

 

##创建出证订单表中存证编号为null的情况下更新所用存储过程
create procedure evi_order_refs_eid_deal()
begin
declare original_eviId varchar(50);
declare evidenceEid varchar(50);
declare done int default 0;
declare mark varchar(2);
declare eid_value varchar(50);
declare type_value int default 0;
declare eid_mark varchar(50);
# declare existence boolean ;
##
declare cur cursor for select eviId  from evi_order_refs where evidenceEid is null order by createTime desc;
##异常处理(触发sql语句失败,执行结束)
declare continue handler for sqlstate 09000 set done = 1;
open cur;
    ##取出游标值至变量中
    fetch next from cur into original_eviId;
  repeat
    if not done then 
       
                    select type into type_value  from osv_service_evidence where id = original_eviId;
                    #逻辑判断,如果eviId确实在存证表中无记录,直接忽略该条出证记录
                    
                    select e.eid into eid_value from osv_service_evidence e where id = original_eviId;
                    #逻辑判断,如果eviId确实在存证表中无记录,直接忽略该条出证记录
                    if(0 =type_value|null = eid_value) then fetch next from cur into original_eviId;
                    end if;
                        
                    if     type_value =40 then set mark = O;set eid_mark=concat(mark,eid_value);update evi_order_refs set evidenceEid = eid_mark where eviId = original_eviId;
                    elseif type_value =11 then set mark = S;set eid_mark=concat(mark,eid_value);update evi_order_refs set evidenceEid = eid_mark where eviId = original_eviId;else  set done = 0;
            end if;
          end if;
        #if(done = 1) then leave cur;
        
        ##重新抓取数据进入循环
    fetch next from cur into original_eviId;
##结束循环
until done end repeat;
##关闭游标
close cur;
end ;

 





以上是关于求教jsp分页显示的问题,如何循环并分页取得参数?的主要内容,如果未能解决你的问题,请参考以下文章

C#winform如何实现数据库查询并分页

mysql存储过程嵌套循环并分页处理数据

springMVC怎么实现分页显示啊?就是这种效果!

A.PHP读取txt文本文件并分页显示的方法

Java如何根据条件查询相应的数据并分页

scroll事件实现监控滚动条并分页显示示例(zepto.js)