简体   繁体   中英

Convert arrayList to javascript array

I am sending an arrayList from a java file to a .jsp file

In order to receive that array I used the following code

var words = 
        [
            <c:forEach begin="0" items="${requestScope.WordList}" var = "word">
                word,
             </c:forEach>
        ];

however it is not working .. any Idea of how to do it ?

Possible fix (Bad fix):

var words = 
    [
        <c:forEach items="${requestScope.WordList}" var="word" 
         varStatus="status">
          "${word}"<c:if test="${not status.last}">,</c:if>
        </c:forEach>
    ];

OR

Convert the Java ArrayList to JSON String, and use JSON.parse() to get Javascript object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM