在javascript数组中推送java数组

时间:2012-03-13 22:22:52

标签: java javascript java-ee web-applications

我通过ABC.jsp中的request.getAttribute获取数组char [16] [16]:

<% char [][] ab = new char [16][16];
ab = (char [][]) request.getAttribute("grid"); %>

<script lang="text/javascript">
var cArr = new Array(16);
for(var c=0; c<16; c++)
    cArr[c] = new Array(16);
</script>

有没有办法将值从'ab'推送到cArr而无需手动执行256个语句?

1 个答案:

答案 0 :(得分:1)

<%
    String[] js = new String[16];

    for (int i=0; i<ab.length; i++) {
        js[i] = "'" + Arrays.toString(ab[i]).replace(", ", "', '") + "'";
    }

    String jsStr = Arrays.toString(js);
%>

<script lang="text/javascript">
var cArr = [
            <%= jsStr %>
            ];
</script>