wood burning stoves*
The moose likes JSP and the fly likes Displaying a datagrid on a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying a datagrid on a JSP" Watch "Displaying a datagrid on a JSP" New topic
Author

Displaying a datagrid on a JSP

Divya Chandrasekhar
Greenhorn

Joined: Jun 04, 2011
Posts: 21

Hi,
I have a small form, which when filled would hit a DB, fetch some data and this data needs to be populated onto a JSP page.
My questions are:
1. Since we are talking about a datagrid being displayed, can we fetch a resultset and set it to session/ request scope - I think this is a bad design choice. But how else would I display the data?
2. If I do not use the above approach, how else can I do it? Can I store the data in a collection that can be set to request scope and display from there?
Thanks,
Divya


SCJP 6: 96% SCWCD 5: 98%
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


There would be too much application processing logic on the JSP if you were to pass the ResultSet object. I would suggest you populate a Bean which has all the necessary fields and pass that to the JSP. Once inside the JSP you could then iterate through the List and display the necessa\ry data (with proper formatting) as required.
Divya Chandrasekhar
Greenhorn

Joined: Jun 04, 2011
Posts: 21

Hi Raj,

A small example would help...

Thanks,
Divya
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


The algorithm would look like :-

1. Fetch the ResultSet.
2. Loop: contents of the ResultSet.
3. Populate the bean fields with values in the ResultSet.
4. Add the Bean to a List.
5. Continue Loop for the entire ResultSet.
6. Pass the List<Bean> in the request to the JSP.
7. Loop: In the JSP iterate through the above List.
8. Display the needed fields in the bean.
9. Continue the Loop for the entire List.
Divya Chandrasekhar
Greenhorn

Joined: Jun 04, 2011
Posts: 21

Thanks Raj,

Will try this out!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying a datagrid on a JSP