This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes How to iterate through c:forEach tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to iterate through c:forEach tag" Watch "How to iterate through c:forEach tag" New topic
Author

How to iterate through c:forEach tag

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
How to find the length of the array that we iterate through in <c:forEach> tag.

Suppose we have a scenario in which I have iterate upto (n-1) element?

String[] names = {"a", "b", "c", "d"};

This can be done like (names.length-1)
for(int i=0; i<(names.length-1); i++) {
}
request.setAttribute("Names", names);

<c:forEach var="name" items=${Names} end="?" />

What should I specify for "end" attribute to achieve the same.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

What version of JSP?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
JSP 2.0
JSTL 1.1
Tomcat 5.5.9
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

Check out the fn:length() JSTL function.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Thanks Bear.
 
 
subject: How to iterate through c:forEach tag
 
Similar Threads
Using EL to retrive data from Arraylist
Using JSTL forEach with a custom tag
iterate dynamic attribute in tag files
help in JSP
java 1.5 list iteration using jstl tag