• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying Table Data

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a JSP page that displays data from a table. I can build something but I thought I would check first to see if something exists that does this already. A design pattern or set of custom tags that process a resultset?

Anyone know of something like this?

Thanks,

Luke
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is generally considered bad design to have JSPs access a DB directly, or even to use java.sql classes in a JSP page. JSTL does have SQL tags you can use, though, if you need to do it. On the other hand, if the question is more about creating the table, you can use something like the displaytags library (on SourceForge).
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I have been looking at the JSTL DB access tags.

I guess my decision comes down to where I want the DB logic.

Personally I would like to keep it in a Java class (this way I have a connection pool and proper logging).

Once I get to this part of the application (later today I think) I would like to just try putting a resultset in an attribute and writing out the data with a JSTL forloop. If that doesn't work I can create an object (with getters and setters) for each table I want to display. This should simply displaying the data.

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to just try putting a resultset in an attribute and writing out the data with a JSTL forloop


Not the best of approaches. It's generally a good idea to not hold onto db resources that long. I'd grab the resultset in my back-end data access code, copy the data into beans for use on-page, and release the resultset at first opportunity.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, a result set is not a construct that forEach will be able to loop over.
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Makes a lot of sense, plus you just saved me a lot of trial and error. I think a bean type object wrapping the results will be perfect.

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, if your data doesn't need any semantics and just needs to be displayed in a table, I've often just captured it in an Object[][] matrix to send to the page.
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm. That is a good idea. All I need to do is display it. This sounds like the easiest solution.

Thanks!

Luke
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!