Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

forEach with a resultSet ?  RSS feed

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone tell me how to use the JSTL tag c:forEach with a resultSet which is generated in a bean, NOT with the <sql:query tag.

I get a "Don't know how to iterate over supplied "items" in <forEach>" exception when just using the resultSet from the bean.

Thanks.

Dave.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. And that's on purpose since that's not a very good practice. Result sets are tied to database connections which are resources that should be freed as soon as possible. The customary approach is to fetch the data from the result set at the lowest level possible (most definitely not within the JSP) and use it to populate EL-friendly structures (Collections, Maps and Beans) that are subsequently passed to the JSP page for display.

Since you are using the JSTL you should be aware that it is most effective when used in a Model 2 environment -- one in which processing takes place in servlet controllers, while JSPs are used solely for the purpose of generating the display.
[ March 20, 2005: Message edited by: Bear Bibeault ]
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm I see, thanks Bear. I think I need to do a bit more reading on Maps/Arraylists etc to see what would be most appropriate.

It seems a bean is ideal to access a single record or to call methods of the bean straight from the jsp, but any tabular data is a bit trickier.

Thanks also for your contributions to my other questions.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you're showing just a table of data, sometimes nothing beats good old Object[][].
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!