Vector 分页显示

yycxx 2005-04-21 03:01:44
JSP页面中我得到了一个数据结果集,用getAttribute(String)得到的.
存在一个Vector中,我要把它分页显示出来。
点下一页就显示下一轮记录
应该臬做?关键是点下一页时该写什么代码?
...全文
279 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
yycxx 2005-04-27
  • 打赏
  • 举报
回复
已经弄定了,谢谢各位
我点击下一页时把页码值作为参数传递,提交本页,就可以刷新显示了
yycxx 2005-04-22
  • 打赏
  • 举报
回复
up
xiaowenand 2005-04-22
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*" %>
<jsp:useBean id="offLogBean" class="gbook.Operation" scope="page"/>
<%
//int isadm = offLogBean.getGrade(request,response);
//out.println("isadm:"+isadm);
int num = offLogBean.UserShow(request,response);
boolean list = offLogBean.UserList(request,response);
out.println("List=" +list);
boolean bool = offLogBean.isAdmin(request,response);
out.println(bool);
out.println("num="+num+"()");
if(num == 2)
response.sendRedirect("Atr_Login.jsp");
%>
<jsp:useBean id="sumList" class="java.util.Vector" scope="request" />
<jsp:useBean id="UserList" class="java.util.Vector" scope="request"/>
<%
String Username="";
String Password="";
String Grade="";
int UserID=0;
int pageRow = ((Integer)request.getAttribute("pageRow")).intValue();
int totalRow = ((Integer)request.getAttribute("totalRow")).intValue();
int thispage = ((Integer)request.getAttribute("thisPage")).intValue();
int maxpage = ((Integer)request.getAttribute("maxPage")).intValue();
out.print(thispage +"<br>");
out.print(maxpage);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" type="text/css" href="../conn/style.css">
</head>
<body>
<div align="center">
<center>
<table border="0" width="92%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center">
<p align="center"><br>
点击相关总结察看<br>公开是给全公司同事查看<br>
<form name="searchsoft" method="POST" action="total.jsp">
查找总结: <input class=smallInput type="text" name="title" size="13"><input type="submit" value="查 询" name="title">
<%
String User = "";
int ID = 0;%>
<select name="UserID">
 <%
if(UserList != null){
for(int i=0; i<UserList.size()/2; i++){
int j = i*2;
User = (String)UserList.elementAt(j+1);
ID = ((Integer)UserList.elementAt(j)).intValue();
out.print("<option value="+ID+">"+User+"</option>");
%>
<%}}%>    
</select>
<%out.println(session.getMaxInactiveInterval());
%>       
</form>

<div align="center">
<div align="center"><center>
<table border="1" cellspacing="0" width="590" bordercolorlight="#000000" bordercolordark="#FFFFFF" cellpadding="0">
<tr>
<td width="78" align="center" bgcolor="#D0D0D0" height="20"><strong>ID</strong></td>
<td width="162" align="center" bgcolor="#D0D0D0"><strong>用户名</strong></td>
<td width="92" align="center" bgcolor="#D0D0D0"><strong>密码</strong></td>
<td width="59" align="center" bgcolor="#D0D0D0"><strong>权限</strong></td>
<td width="63" align="center" bgcolor="#D0D0D0"><strong>查看</strong></td>
<td width="64" align="center" bgcolor="#D0D0D0"><strong>编辑</strong></td>
<td width="58" align="center" bgcolor="#D0D0D0"><strong>删除</strong></td>
</tr>
<%
if(sumList!=null)

{
//for(int i=sumList.size()/4-1;i>=0;i--)
for(int i=0;i<sumList.size()/4;i++)
{
int j=i*4;
UserID=((Integer)sumList.elementAt(j)).intValue();
Username=(String)sumList.elementAt(j+1);
Password=(String)sumList.elementAt(j+2);
Grade=(String)sumList.elementAt(j+3);


%>
<tr>
<td height="23" width="78">
<p align="center"> <a href="Atr_view.jsp?UserID=<%=UserID%>"><%=UserID%></a>
</td>
<td width="162">
<p align="center"><%=Username%>
</td>
<td width="92">
<p align="center"><%=Password%>
</td>
<td width="59">
<p align="center"><%=Grade%>
</td>
<td width="63">
<p align="center"><a href="Atr_view.jsp?UserID=<%=UserID%>">View </a>
</td>
<td width="64"><div align="center"><a href="Atr_edit.jsp?UserID=<%=UserID%>">Edit</a></div></td>
<td width="58">
<p align="center"><a href="Action.jsp?action=del&UserID=<%=UserID%>">Delete </a>
</td>
</tr>
<%}}%>
</table>
<form name="form2" method="post" action="total.jsp">
<table cellspacing="5" cellpadding="3" border="0" width="590">

<tbody>

<tr>

<td width="41%">第<%=thispage%>页 共 <%=totalRow%>条记录 每页 <%=pageRow%>行</td>

<td width="12%"><div align="center">共<%=maxpage%>页</div></td>

<td width="12%">

<% if(thispage>1){%>

<a href="total.jsp?page=<%=thispage-1%>">上一页</a>

<%}%>

</td>

<td width="11%">

<% if(thispage<maxpage) {%>

<a href="total.jsp?page=<%=thispage+1%>">下一页</a>

<%}%>

</td>

<td width="24%">第

<select name="page">

<% for(int p=1;p<=maxpage;p++){ %>

<option value="<%=p%>"><%=p%></option>

<%}%>

</select>

页 <input type="submit" name="Submit" value="提交">

</td>

</tr>

</tbody>

</table>
</form>


</center></div>
</div></td>
</tr>
</table>
</center></div>
</body>
</html>

xiaowenand 2005-04-22
  • 打赏
  • 举报
回复
public int UserShow(HttpServletRequest req,HttpServletResponse res) throws Exception{
boolean islogin = isAdmin(req,res);
int num = 1;
if(!islogin)
num = 2;

String sql1 = "select * from UserTable order by UserID desc";
String sql2 = "select count(UserID) from UserTable";
Vector sumList = new Vector();
String page = req.getParameter("page");
if(page == null)
page="1";

int thisPage = new Integer(page).intValue();
int totalRow=0;
int pageRow=5;
int startRow=1;
int endRow=pageRow;
int maxPage=0;

DbLink db = new DbLink();
con = db.getConn();
totalRow = db.total(sql2);
if(totalRow % pageRow == 0){
maxPage = totalRow/pageRow;
}else{
maxPage = totalRow/pageRow+1;
}
if(thisPage<1)
thisPage = 1;
if(thisPage>maxPage)
thisPage = maxPage;
req.setAttribute("thisPage",new Integer(thisPage));
//thisPage=maxPage-thisPage+1;
if(thisPage>1&&thisPage<maxPage)
{
startRow=(thisPage-1)*pageRow+1;
endRow=thisPage*pageRow;
}
else if(thisPage>=maxPage)
{
startRow=(maxPage-1)*pageRow+1;
endRow=totalRow;
}
rs = db.executeQuery(sql1);
try{
if(startRow>= 1){
rs.absolute(startRow);
int i = 0;
while(i<pageRow){
sumList.addElement(new Integer(rs.getInt("userid")));
sumList.addElement(rs.getString("Username"));
sumList.addElement(rs.getString("Password"));
sumList.addElement(rs.getString("Grade"));
i++;
rs.next();
}
}
}catch(Exception e){
e.printStackTrace();
}
finally{
con.close();
}
if(sumList!=null)
req.setAttribute("sumList",sumList);
req.setAttribute("maxPage",new Integer(maxPage));
req.setAttribute("totalRow",new Integer(totalRow));
req.setAttribute("pageRow",new Integer(pageRow));

return num;
}




jhb810624 2005-04-22
  • 打赏
  • 举报
回复
写一个页面信息的java,做一下翻页的控制
jihanzhong 2005-04-22
  • 打赏
  • 举报
回复
给个例子,存成html就可以使用:


<html>
<head>
<title>基于客户端的分页导航—太平洋电脑网</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<xml id="oXML">
<forums> <forum>
<name>[FLASH技术交流]</name>
<moderator ><![CDATA[版主:赢点儿 chenye_1976 holybozo laiy.net]]></moderator>
<description ><![CDATA[新手请尽管提问,老手尽管来切磋,让学习和帮助都成为一种乐趣。]]> </description>
</forum> <forum>
<name>[Action Script讨论区]</name>
<moderator ><![CDATA[版主:hnyashiro crazydevil horidream]]></moderator>
<description ><![CDATA[Action Script应用,包含flash MX讨论]]> </description>
</forum> <forum>
<name>[Macromedia Studio MX 2004讨论学习区]</name>
<moderator ><![CDATA[版主:AOL kissall 我佛山人]]></moderator>
<description ><![CDATA[交流学习Macromedia Studio MX 2004心得与经验,欢迎提供系统教程和资料翻译.新]]> </description>
</forum> <forum>
<name>[Flash动画技术区]</name>
<moderator ><![CDATA[版主:歪马秀 拾荒 林℃]]></moderator>
<description ><![CDATA[中级动画爱好者进级技术版块,在这里我们讨论怎样制作动画造型,动作,背景等制作技术. ]]> </description>
</forum> <forum>
<name>[Flash游戏技术区]</name>
<moderator ><![CDATA[版主:AOL windson2002]]></moderator>
<description ><![CDATA[这里只讨论Flash游戏技术. ]]> </description>
</forum> <forum>
<name>[图形处理与视觉传达]</name>
<moderator ><![CDATA[版主:颜志 保镖豆豆 wxb_snowwolf 風過無痕]]></moderator>
<description ><![CDATA[一切创作的基础来源于图形处理的基本功,Flash也不例外。喜欢这个的朋友不妨在这里交流,探讨。]]> </description>
</forum> <forum>
<name>[手绘艺术与角色设计]</name>
<moderator ><![CDATA[版主:颜志 绯水]]></moderator>
<description ><![CDATA[手绘艺术与角色设计]]> </description>
</forum> <forum>
<name>[Flash资源共享]</name>
<moderator ><![CDATA[版主:kissall 木头 CRAZYNO1]]></moderator>
<description ><![CDATA[Flash相关资源和软件的交流.]]> </description>
</forum> <forum>
<name>[Flash 3d 技术专版]</name>
<moderator ><![CDATA[版主:白雪飘扬]]></moderator>
<description ><![CDATA[讨论怎样让flash里面的物体三维运动起来]]> </description>
</forum> <forum>
<name>[网页设计与编程]</name>
<moderator ><![CDATA[版主:海光 我佛山人 erik168]]></moderator>
<description ><![CDATA[我们讨论所有和网页设计有关的东西]]> </description>
</forum> <forum>
<name>[精品WEB-SITE]</name>
<moderator ><![CDATA[版主:梵天 chenglei4u]]></moderator>
<description ><![CDATA[精品WEB-SITE和FLASH动画的展示专版]]> </description>
</forum> <forum>
<name>[闪吧电脑学校]</name>
<moderator ><![CDATA[版主:Xray 蓝.蜗牛]]></moderator>
<description ><![CDATA[计算机的世界,由你我来探讨。你遇到的各类问题,我们会帮助你。(软硬兼施+网络)]]> </description>
</forum> </forums>
</xml>
<style>
table{border-collapse: collapse;width:600px;font:normal 12px Tahoma;background:#EEEEEE}
button{border:1px solid #666666;background:#EEEEEE}
</style>
<center>
<table bordercolor="#333333" border="1" cellspacing="0"
cellpadding="3" datasrc="#oXML" dataPageSize="3" id="dTable">
<tr>
<td width="25%" rowspan="2" align="center" valign="top"><span datafld="name" /></td>
<td width="75%" height="20"><span datafld="moderator" /></td>
</tr>
<tr>
<td><span datafld="description" /></td>
</tr>
</table>
<table border="0" cellspacing="0"
cellpadding="3" >
<tr>
<td align="right" colspan="2"><button onClick="dTable.firstPage()">首页</button><button onClick="dTable.previousPage()">上一页</button><button onClick="dTable.nextPage()">下一页</button><button onClick="dTable.lastPage()">尾页</button></td>
</tr>
</table>

</body>
</html>
jihanzhong 2005-04-22
  • 打赏
  • 举报
回复
如果你不愿意刷新,把数据全写在一个页面也可以!
用<div ></div>分层显示,脚本控制显示哪一层!一层既一页

或则采用xml数据池
extraleo 2005-04-22
  • 打赏
  • 举报
回复
我觉得一个好的设计,分页应该是数据分开!就是没有数据,只要给定纪录的总条数就可以翻页
Voxer 2005-04-22
  • 打赏
  • 举报
回复
select * from table where rownum<10 minus select * from table where rownum<5;
取第5条到第10条
orcale下可以,其他数据库不太清楚

cyz99 2005-04-22
  • 打赏
  • 举报
回复
这种问题直接使用displaytag来做显示是最好不过的!
cuij7718 2005-04-22
  • 打赏
  • 举报
回复
有句话更正:上一页和下一页连接里包含参数上一页的数字和下一页的数字
cuij7718 2005-04-22
  • 打赏
  • 举报
回复
晕,不是说了吗,点击下一页再查询数据库,这样效率是高而不是低,把记录全部放入vector这样效率才会很低,下一页这个连接里包含参数上一页的数字和下一页的数字,提交到servlet,servlet里面获得页数和查询条件,在查询数据库就可以了
King6860 2005-04-22
  • 打赏
  • 举报
回复
如果数据库里面的记录是2000000 条,你还放在VECTOR 中吗???
考虑用其他的方法吧。。
yycxx 2005-04-21
  • 打赏
  • 举报
回复
要简单的跳转代码
yycxx 2005-04-21
  • 打赏
  • 举报
回复
晕啊,我是要知道怎么跳转到下一页的输出
要怎样输出我知道,怎么跳转?
烦。。。。。
8586648 2005-04-21
  • 打赏
  • 举报
回复
int x=0;
//page当前是第几页,rowspage每页有几行/rs为记录集
while (rs.next()) {
if (x > (page - 1) * rowspage - 1) { //过滤数据,得到所耍数据
Vdwmc.add( (rs.getString(2).trim() == null) ? "" : rs.getString(2)); //单位名称
Vjp.add( (rs.getString(3) == null) ? "" : rs.getString(3)); //简拼

Vlxr.add( (rs.getString(4) == null) ? "" : rs.getString(4)); //联系人
Vlxdh.add( (rs.getString(5) == null) ? "" : rs.getString(5)); //联系电话
Vemail.add( (rs.getString(6) == null) ? "" : rs.getString(6)); //电子信箱
Vdz.add( (rs.getString(7) == null) ? "" : rs.getString(7)); //地址
}
x++;

}
yycxx 2005-04-21
  • 打赏
  • 举报
回复
up
yycxx 2005-04-21
  • 打赏
  • 举报
回复
关键是点下一页时该写什么代码?
ipv 2005-04-21
  • 打赏
  • 举报
回复
传递2个参数
当前第几页
每页多少条
就好了阿
根据vector的大小
循环显示那一部分就好了阿
yycxx 2005-04-21
  • 打赏
  • 举报
回复
这样效率不好,
我是想知道用我现在的方法怎么做
加载更多回复(1)

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧