my dog learned polymorphism*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 61448
    
  67

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: 61448
    
  67

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

Joined: Nov 15, 2004
Posts: 1026
Thanks Bear.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to iterate through c:forEach tag