<% String[] title = { "姓名 ", "学号 ", "性别 ", "年龄 "}; %> <script> var title=new Array(); <% for(inti=0;i <title.length;i++){ %> title[ <%=i%> ]= " <%=title[i]%> "; <% } %> </script>
如果JAVA数组为ArrayList类型,则:
<% DataDB datadb = new DataDB(); ArrayList<String> arraylistprojectname = datadb.getALLprojectname();//获取所有项目的名称 %> <script type="text/javascript"> var JSarraylistProjectname = new Array(); <% for(int i=0;i <arraylistprojectname.size();i++){ %> JSarraylistProjectname[<%=i%>] = "<%=arraylistprojectname.get(i)%>"; <% } %> alert(JSarraylistProjectname[0]); </script>