I have a list of strings on my server which I am trying to get to the client in the form of an array. The code I am attempting to use is the following:
Within the js
For me this solution has worked. First of all You should make a JSONArray and use it's toJSONString() method. This method converts the list to JSON text. The result of it is a JSON array.
<%
List exampleList = new ArrayList<>();
exampleList.add("Apple");
exampleList.add("Orange");
exampleList.add("Lemon");
JSONArray fruitList = new JSONArray();
fruitList.addAll(exampleList);
%>
In your JSP page you should invoke the toJSONString() method of the list, and pass the JSON text to a JavaScript array.
(Optionally You could make a simple getter method for the list. In case if you only instantiate the JAVA class - which has the list field - int the JSP page.)