How I can use JSP/Java Bean to make a resultset show in different pages?(100分)

  • 主题发起人 主题发起人 pengxuan
  • 开始时间 开始时间
P

pengxuan

Unregistered / Unconfirmed
GUEST, unregistred user!
How I can use JSP/Java Bean to make a resultset show in different pages?
Thank you.
 
you can add the following html code in your page:
〈a href="your.jsp" target="_blank"〉...〈/a〉
or
〈form action="your.jsp" target="_blank"〉
...
〈/form〉
 
pengxuan的意思很可能是作成分多页显示的形式,可以直接跳转到指定
页面(比如前页,后页,或直接输入页码等),而不是在另开的浏览器
窗口中显示。
在asp中,由于ado的recordset有pagesize属性,因而实现分页显示比较
容易,在jsp中,jdbc是否提供了类似的属性呢?jsp如何完成这种功能呢?
请高手指点迷津。
 
Birdkiller's words is exactly what I want to ask.
Please help me answer this question.Thank you.
 
you can try to cut the resultset to some small part,and show them
one by one!
 
既然已经想到用Java Bean,为什麽不用呢?
可以将JaveBean的scope设置成Session,在Bean中保存查询结果,
在不同的页面显示ResultSet中不同的部分。
 
传相关参数, 返回相关的东西, 最好不用数据集,
而用 IteratorList Iterator 或者干脆数组。
 
先定义bean类Order,
如 class Order {
private String custid;
private String goodid;
pirvate Number amount;
....
// setXXX and getXXX function
}

Vector orderList = new Vector();
while ( rs.next() ) {
....// create order for current record
orderList.addElement( currorder );
}
session.putValue( orderList);
然后在jsp中定义一个参数pos记住orderList的当前位置
....
<%@page session="true" import="Order" %>
<% for ( int i= pos;
i <pos+numPerPage;
i++ ) {
Order order = (Order)orderList.elementAt(i);
..//show data
%>
 
可以用算法,将各页下的连结中传不同的参数,然后在下页中读入该参数,然后用
resultset.next()将光标移至相应位置,显示一部分数据,如何,
嘻嘻,老板那里我的例程,或者找birdkiller.
 
我和zhouhe的方法是一样的。
spear的方法我也想过的,不过有个问题,我对java的自动收集机制一直不放心。
说这个Vector什么时候会释放空间呢?
还有,这个Vector取得后,如果数据库又有了变化,就不能及时反映了。
来不及了,我要去接人。
晚上过来贴代码。
 
package apacs.util;
/**
* Creation date: (9/13/2000 8:48:22 PM)
* @author: XiaogangCao
*/
public class PageHelper {
/**
* PageHelper constructor comment.
*/
public PageHelper() {
super();
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isFirstPage(int RowCount, int RowPerPage, int PageNO)
{
if (RowCount == 0)
return true;
return PageNO==0;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isFirstPage(apacs.db.Query q, int RowPerPage, int PageNO)
{
if (q.recordCount() == 0)
return true;
return PageNO==0;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isLastPage(int RowCount, int RowPerPage, int PageNO)
{
if (RowCount == 0)
return true;
return PageNO==pageCount(RowCount,RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isLastPage(apacs.db.Query q, int RowPerPage, int PageNO)
{
if (q.recordCount() == 0)
return true;
return PageNO==pageCount(q,RowPerPage)-1;
}
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args)
{
int RowCount = 101;
int RowPerPage = 25;
System.out.println(pageCount(RowCount,RowPerPage));
System.out.println(pageRangeTop(RowPerPage,4));
System.out.println(pageRangeBottom(RowCount,RowPerPage,4));
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:50:11 PM)
* @return int
* @param RowCounts int
* @param RowPerPage int
*/
public static int pageCount(int RowCount, int RowPerPage)
{
return (RowCount + RowPerPage-1)/ RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:50:48 PM)
* @return int
* @param q apacs.db.Query
* @param RowPerPage int
*/
public static int pageCount(apacs.db.Query q, int RowPerPage)
{
return (q.recordCount() + RowPerPage-1)/ RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeBottom(int RowCount,int RowPerPage, int PageNO)
{
if (!pageValid(RowCount,RowPerPage,PageNO))
return -1;
if (isLastPage(RowCount,RowPerPage,PageNO))
return RowCount-1;
return ((PageNO+1) * RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeBottom(apacs.db.Query q,int RowPerPage, int PageNO)
{
if (!pageValid(q,RowPerPage,PageNO))
return -1;
if (isLastPage(q,RowPerPage,PageNO))
return q.recordCount()-1;
return ((PageNO+1) * RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeTop(int RowPerPage, int PageNO)
{
return PageNO * RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:54:33 PM)
* @return boolean
* @param RowCount int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean pageValid(int RowCount, int RowPerPage, int PageNO)
{
return ((PageNO >=0) &amp;&amp;
(PageNO<pageCount(RowCount,RowPerPage)));
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:54:33 PM)
* @return boolean
* @param RowCount int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean pageValid(apacs.db.Query q, int RowPerPage, int PageNO)
{
return ((PageNO >=0) &amp;&amp;
(PageNO<pageCount(q,RowPerPage)));
}
}
 
public boolean gotoRow(int realRow) throws ArrayIndexOutOfBoundsException
{
if (!result.isOpen())
{
throw new ArrayIndexOutOfBoundsException ("Row is out of bounds.");
}

// Handle an out of bounds index by throwing an exception
if (realRow > result.getNumRowsInCache())
{
throw new ArrayIndexOutOfBoundsException ("Row is out of bounds.");
}

try
{
result.setCurrentRow(realRow);
}
catch (Exception e)
{
System.out.println("Error occurred in com.ibm.db.SelectResult.setCurrentRow");
e.printStackTrace();
}
return true;
}
 
呵呵, 文档写的挺标准的嘛。
 
那里那里...
都是VisualAge自己生成的。
faint,贴代码长度还有限制,怎么只有一半了...
 
多人接受答案了。
 

Similar threads

A
回复
0
查看
932
Andreas Hausladen
A
A
回复
0
查看
805
Andreas Hausladen
A
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
后退
顶部