• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Displaying a datagrid on a JSP

 
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,

A small example would help...

Thanks,
Divya
 
Rajkamal Pillai
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Raj,

Will try this out!
 
reply
    Bookmark Topic Watch Topic
  • New Topic