Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object type sent to a JSP from servlet

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic