Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Boell Fischer   on Jan 05 In Java Category.

  
Question Answered By: Jamie Williams   on Jan 05

This is a very simple way of doing it. Note, I did not clear the
cache. So the loaded table will permanently be loaded until user
session dies. Also if 1000 users load the page at the same time,
there'll be 1000 copies cached.

Let say your jsp  page is named "listing.jsp"

listing.jsp

Request parameter
name: page
value: any number
description: Display page number x of the 120 records. Eg. 0 will
list records  1 to 10, 2=>11 to 20, and so on.

In listing.jsp

<%
synchronized (session) {
// if session attribute ArrayList "tablecache" is null
// then
// query db and add records to session attribute "recordcache"
// endif

// Note: consider storing in application scope to save memory
// Note: but need to release object once in a while.
}

ArrayList records = (ArrayList)session.getAttribute("tablecache");

int showPage = 0; // default
try {
// parse parameter "page"
// Set showPage to parsed value
} catch (NumberFormatException e){
// ignore
}

int lower = showPage * 10;
int upper = lower + 10;

// Check boundaries

// Display your records
for (int i=lower; i<upper; i++){
out.println(records.get(i));
}
// create navigation bar here
%>

Share: 

 
 
Didn't find what you were looking for? Find more on Displaying 10 records a time Or get search suggestion and latest updates.


Tagged: