JSTL: How do I set an array variable?

Discussion in 'Java' started by Derek Mahar, Jul 17, 2003.

  1. Derek Mahar

    Derek Mahar Guest

    How do I use the JSTL <c:set> to set an array variable that I may
    subsequently iterate over with <c:forEach>?

    Thanks,

    Derek
    Derek Mahar, Jul 17, 2003
    #1
    1. Advertising

  2. Derek Mahar

    Scott Yanoff Guest

    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><c:eek:ut value="${brewer}">
    </c:forTokens>

    Good luck,
    --
    -Scott
    | http://www.yanoff.org | AOL IM: SAY KJY
    Scott Yanoff, Jul 17, 2003
    #2
    1. Advertising

  3. Derek Mahar

    DoggieDaddy

    Joined:
    Jun 7, 2011
    Messages:
    1
    JSTL Setting Arrays

    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: <c:eek:ut value="${yankee}" /><br />
    </c:forEach>
    DoggieDaddy, Jun 7, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick DeBay

    JSTL c:set exception

    Rick DeBay, Jan 13, 2004, in forum: Java
    Replies:
    2
    Views:
    3,516
    Rick DeBay
    Jan 14, 2004
  2. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    956
    Robert Mark Bram
    Dec 15, 2004
  3. Replies:
    0
    Views:
    6,679
  4. Replies:
    2
    Views:
    580
  5. DaFoot
    Replies:
    1
    Views:
    1,671
    DaFoot
    Oct 23, 2008
Loading...

Share This Page