Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSTL: How do I set an array variable?

Reply
Thread Tools

JSTL: How do I set an array variable?

 
 
Derek Mahar
Guest
Posts: n/a
 
      07-17-2003
How do I use the JSTL <c:set> to set an array variable that I may
subsequently iterate over with <c:forEach>?

Thanks,

Derek
 
Reply With Quote
 
 
 
 
Scott Yanoff
Guest
Posts: n/a
 
      07-17-2003
Derek Mahar wrote:
> How do I use the JSTL <c:set> to set an array variable that I may
> subsequently iterate over with <c:forEach>?


A weak solution is to set a delimited string to simulate and array:
<c:set var="brewers">Richie Sexson, Eric Young, Ben Sheets, Geoff
Jenkins, Brady Clark, Scott Podsednik, Keith Ginter</c:set>

Then, use forTokens to iterate through it:
<c:forTokens items="${brewers}" delims="," var="brewer">
<li><cut value="${brewer}">
</c:forTokens>

Good luck,
--
-Scott
| http://www.yanoff.org | AOL IM: SAY KJY

 
Reply With Quote
 
 
 
 
DoggieDaddy DoggieDaddy is offline
Junior Member
Join Date: Jun 2011
Posts: 1
 
      06-07-2011
THIS:
<%
String[] yankees = {"Jeter", "Posada", "Rodriguez", "Kanoe", "Rivera", "Swisher"};
pageContext.setAttribute("yankees",yankees, PageContext.REQUEST_SCOPE);
%>

IS THE SAME AS THIS:
<c:set var="yankees" scope='request'>"Jeter", "Posada", "Rodriguez", "Kanoe", "Rivera", "Swisher"</c:set>

AND BOTH CAN BE PRINTED LIKE THIS:
<c:forEach var="yankee" items="${yankees}">
Name: <cut value="${yankee}" /><br />
</c:forEach>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Treeview questions - how to set set start node and how to catch click event Alan Silver ASP .Net 0 12-21-2005 10:40 AM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
Unable to set focus to textfield in a applet if browser is set to Sun JRE 1.4 Manav Java 0 10-15-2003 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57