• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object type sent to a JSP from servlet

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I was just wondering what the object type my serlvet should send to the JSP After I do a DB query?
The DB query yields a ResultSet, should I pass this to the JSP which will then loop through and place the relevant information or should it be a HashMap or something else??

Thank you for your thoughts

Regards
Zein
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Result sets and other database resources should never make it as far as the UI. You shoud absrtract the data into whatever stucture makes the most sense, be it beans, a map, a list, an array or other.

Release database resources as quickly as possible, espcially in a threaded environment such as a web application.
[ August 19, 2006: Message edited by: Bear Bibeault ]
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want clients to have direct access to a database, install a database client on their machine. It'll eliminat the need for JSPs altogether!

Okay, I'm being snide. I apologize.

You really want to minimize the amount of data sent to a JSP from a Servlet. Only send what needs to be displayed. And you really don't want to send DataBase objects - they tend not to be too serializable.

Figure out what you need to send to the JSP purely for display purposes, see if there isn't so handsome and sexy collection class you can stuff that into, and then have the JSP do a standard looping over the collection class.

Oh, and make aure you're using the HttpServletRequest for passing that data. It'd be a real waste to use the session ,and have all that data needlessly follow a client around the website.
[ August 27, 2006: Message edited by: Bear Bibeault ]
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic