This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes display resultset from servlet on jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "display resultset from servlet on jsp" Watch "display resultset from servlet on jsp" New topic
Author

display resultset from servlet on jsp

M Ryder
Greenhorn

Joined: May 01, 2008
Posts: 9
Hi,
I am trying to determine the best way to get a resultset from a servlet to display as a report on a jsp page. Any suggestions?
Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Strictly speaking, you should never have a resultset in a servlet. DB access should happen at a lower layer, with non-DB constructs passed up to the UI layer. If you're doing your DB access in a servlet, you're not following best practices (MVC) for web app design.

That said, regardless of where you do the DB access, you should copy the data from the resultset into another construct (Lists, arrays, whatever makes the most sense for the nature of the data) and close the rsultset and statement as soon as possible.

For reporting, are you rolling your own, or using a prefab reporting package? That might dictate what format you transform the resultset data into. For simply showing a grid of data on a JSP, copying the data into a simple Object[][] can work just fine.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
M Ryder
Greenhorn

Joined: May 01, 2008
Posts: 9
Thanks Bear. I will review the mvc.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

That would be best long-term, but did you get the thrust of my post regarding not leaving resultsets open for long periods by copying the data?
M Ryder
Greenhorn

Joined: May 01, 2008
Posts: 9
yes, I got it.. makes sense
 
 
subject: display resultset from servlet on jsp