File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Object type sent to a JSP from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Object type sent to a JSP from servlet" Watch "Object type sent to a JSP from servlet" New topic

Object type sent to a JSP from servlet

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
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

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

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 ]

[Asking smart questions] [About Bear] [Books by Bear]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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 agree. Here's the link:
subject: Object type sent to a JSP from servlet
jQuery in Action, 3rd edition