Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
请求中的javascript数组_Javascript_Html_Arrays_Jstl - Fatal编程技术网

请求中的javascript数组

请求中的javascript数组,javascript,html,arrays,jstl,Javascript,Html,Arrays,Jstl,在此处输入code我有一个来自服务器的变量,它定义了一个Javascript数组列表,表示以下国家: [Belgium,Denmark,Germany,Italy,Portugal,Ireland,India,Morocco,Republic Of Korea]; 从jsp中的请求中获取不带引号的变量: var countries = ${countryList}; 我得到这个错误: SCRIPT1007: Expected ']' 我使用引号没有错误 var countries = '

在此处输入code
我有一个来自服务器的变量,它定义了一个Javascript数组列表,表示以下国家:

[Belgium,Denmark,Germany,Italy,Portugal,Ireland,India,Morocco,Republic Of Korea];
从jsp中的请求中获取不带引号的变量:

var countries = ${countryList};
我得到这个错误:

SCRIPT1007: Expected ']' 
我使用引号没有错误

var countries = '${countryList}';
但结果并非预期。我想访问

'Belgium' as countries[0] 
'Denmark' as countries[1] 

'B'改为国家[0]
'e'国家[1]
等。

您将服务器端和客户端混合使用。您需要使用JSTL迭代列表,以便构建JavaScript数组:

var countries = [];
<c:forEach items="${countryList}" var="country"> 
    countries.push('${country}');
</c:forEach>
var国家=[];
国家。推送(“${country}”);

为什么要用javascript重建数组?为什么不在服务器上构建它并将其传递给javascript?