Chris --
I'm unsure whether you can do it through jsp:useBean, but we do something
similar in a Tag: keep Database results in the session as an array. It does
speed subsequent pages quite a bit, but slows down the first one as the whole
ResultSet is processed.
In our code, we just declare an array of arrays, fill it, and set it in the
session:
<code>
String[][] fields = new String[rowCount][colCount];
// code to fill from the database goes here
session.setAttribute("fields", fields);
</code>
To retreive:
<code>
String[][] fields = (String[][]) session.getAttribute("fields");
</code>
You could use scriptlets or a custom tag to do this if you wanted to. In our
case, we implemented as a custom tag that takes a SQL query and a couple
parameters (rows per page, etc) and outputs an HTML table complete with
"next", "prev", "first", "last" buttons. Sure saves custom coding of the
navigation for large resultsets.
Hope this helps.
-- Tim
>===== Original Message From A mailing list about Java Server Pages
specification and reference <[EMAIL PROTECTED]> =====
>Look at this piece of code from a JSP page:
>
><jsp:useBean id="queryAccounts" class="AccountBean[]" scope="session"/>
>
>This fails miserable, but you get my point... Is there another way to make
>an array persistent throughout the session?
>
>Let me explain: Right now, I have a query that returns 25 rows at a time.
>The problem is performance:
>Everytime the page is accessed, via the 'next' hyperlink (which contains a
>parameter that keeps track of the range of rows to query) it re-performs the
>original query because I can't figure out a way to return records 25 - 50,
>51-75, through SQL.
>
>[pass 1]
>For example, I perform a search query that returns 5000 rows and then I
>store the record_id's into an array called index. Since I want to see the
>first 25 rows, I perform 25 individual queries with the record_id's
>contained in index[0] through index[25] (this part seems like it would be my
>bottleneck, but it isn't). Next, I create a hyperlink that hits this very
>same page, but I pass it a variable named index_range=25.
>[pass 2]
>Same page, I perform that same query that returns 5000 rows and the I store
>the record_id's again. Now index_range says '26', I can perform 25 more
>individual queries with the record_id's contained in index[26] through
>index[50]. This results in the next 25 rows.
>[pass n]
>Same thing, except I check for conditions where there aren't exactly 25 more
>records, etc.
>
>The obvious solution is to perform the search query once, store the
>record_id's into a session-persistent array, then continue to use the 'next'
>hyperlink to keep track of where we are in the record_id index. Then
>browsing through the records would be lightning fast.
>
> Chris Murphy
>OTS Information Systems
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets