• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL- make array of words, then access by index?  RSS feed

 
Steve Eckel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm maintaining a JSP that has the following elements:


This section repeats several times, incrementing. I'd like to collapse it into a for loop, like..



Is this even possible? I have seen forToken but it seems like you can only access array elements of arrays you have passed in on the command object, not objects you've defined locally in the page.
If you want to critique the design decisions of making these things separate objects rather than a collection, believe me that conversation has been had many times.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to go through the parallel arrays in a single loop? Have a look at the c:forEach example here: http://www.tutorialspoint.com/jsp/jstl_core_foreach_tag.htm and you'll see how to use an index in c:forEach. There's an fn:length function which gives you the length of an array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!