Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

forEach with a resultSet ?

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you're showing just a table of data, sometimes nothing beats good old Object[][].
 
What a show! What atmosphere! What fun! What a tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic