0
我需要從jsp將array [aLocations]傳遞給下面的代碼。將JSP數組轉換爲Javascript
<script type="text/javascript">
var aLocations = new Array();
var aTitles = new Array();
var aDetails = new Array();
aLocations = ['keswick,cumbria,uk','grasmere,cumbria,uk','ambleside,cumbria,uk'];
</script>
,如果我試圖這樣,它不工作:
<%
ArrayList<String> myArr = new ArrayList<String>();
myArr.add("keswick,cumbria,uk");
myArr.add("grasmere,cumbria,uk");
myArr.add("ambleside,cumbria,uk");
%>
<script type="text/javascript">
var aLocations = new Array();
var aTitles = new Array();
var aDetails = new Array();
aLocations = <%=myArr%>;
</script>
什麼是從JSP傳遞的最佳方法?
感謝UR快速響應。沒有這個圖書館是不可能實現的? –
我試着按照你提到的,但我得到這個錯誤:「從Object(ArrayList)的方法是未定義類型JSONArray」 –