• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing data from DB and displaying in JSP w/o Struts  RSS feed

 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All -

After reading several threads in this forum it is clear that Struts has become very common in J2EE applications. I'm wondering what options we will have for retrieving data from the database and displaying in JSP if we don't use Struts. Are there any options other than putting the resultset in the request object with DB queries executing in Servlets or in POJOs ?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of my web apps access a database and none use Struts.

Your options are pretty much limitless, but one thing you shouldn't do is to send resultsets to the JSPs. In fact, resultsets, or any other DB details, have no place in the presentation tier at all and should be hidden within a UI-agnostic business layer that abstracts the operations that can be performed from the app.
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response. I would appreciate if you can prodvide couple of examples how you retrive and display database records in JSP. When I was talking about attaching the resultset I was talking about


[ May 24, 2005: Message edited by: Dilip kumar ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're usin a JSP 2.0 compliant container you can do this with JSTL and EL
This is a page that displays an arrayList of beans:
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an open source API that among other things creates text (html, xml,
csv, ...) out of tabular data (collections, arrays, resultsets). Basically,
it separates the data, and presentations formatting as arguments to a
method. Reuse is much higher than you can get with a tag library (which in my opinion are similar to copy and paste code).

The easiest way to use my api is to get data into an Object[][] somehow.
There are many ways to do this. One way is to implement my FDSDataAsRows
interface. I'll use your example to show how it works.


Now assuming you populated the ArrayList per your posting, you can easily create an html table as follows. Creating xml or any format you want is equally easy.





I may have a few syntax errors above. Source forge was down so I typed the code from memory.
[ May 24, 2005: Message edited by: steve souza ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!