Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  6] [ 2]  / answers: 1 / hits: 86553  / 11 Years ago, wed, july 3, 2013, 12:00:00

In my Java code, I have an ArrayList of Strings. I'd like to put this data in a JavaScript variable on a JSP page I'm working on. My first thought was to include it directly, e.g.:



var myArray = <%= arrayList %>;


Unfortunately, when executed, myArray is a string in the format [a,b,c], not an actual JavaScript array. How do I get some data from a Java ArrayList to a JavaScript array?


More From » java

 Answers
42

When you use <%=arraylist%> it calls the toString() on list and prints [a,b,c]



And No,you cannot direclty convert From Java arrayList to javascript array ,Convert the Java ArrayList to JSON String, and use JSON.parse() to get Javascript object.



Have a look at Json objet and Json in java


[#77240] Tuesday, July 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;