Convert arrayList to javascript array

≡放荡痞女 提交于 2019-12-12 02:55:11

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/16133264/convert-arraylist-to-javascript-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!