Create array

Posted on 2005-05-12
Last Modified: 2012-08-13
In JSP I'm trying to create an array.  I've been trying to use <c:set var='items' value='stuff' />

like in a for loop and keeping setting var but i don't think thats working.  How should i go about this?
Question by:corduroy9
    LVL 19

    Accepted Solution

    Well I do not recall any straight way of doing it...

    normally I just add all the strings together in one String ( delimited by say ":" and then use c:split() on it
    LVL 6

    Expert Comment

    try it with the setArray:

    <c:setArray var="row" index="0" value="0"/>
    <c:setArray var="row" index="1" value="1"/>
    <c:setArray var="myArray" index="0" value="${row}"/>

    <c:out value="${myArray[0]}"/>
    <c:out value="${myArray[1]}"/>

    LVL 16

    Expert Comment


    Please let us know in more depth on what do you want if all above solution do not answer your question. I think that manuel_m solution is good enough.

    LVL 2

    Author Comment

    Manuel's idea is what i'm looking for.  Obviously tho I'm not going to want to have static indexes.  I'm going to want this dynamic

    So inside my jsp i'll have a for each loop

    and then I would want something like

    <c:setArray var="row" index=<%i%> value ="$item"/>

    Is that the correct way to have index increment?
    LVL 2

    Author Comment

    also setArray is not recognized... y not
    LVL 35

    Expert Comment

    I don't believe setArray exists in JSTL...  (at least not in 1.1)

    it's not there...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now