You need to realize that JSP is basically a HTML code generator and that CSS/JS is part of the generated HTML output. You need to write JSP code in such way that valid HTML/JS code is generated. A valid JS array of 3 objects with each the properties foo and bar look like this:
var chart = [{
foo: "foo1",
bar: "bar1"
},{
foo: "foo2",
bar: "bar2"
},{
foo: "foo3",
bar: "bar3"
}];
var index;
for(index = 0; index < chart.length; index++) {
var item = chart[index];
alert(item.foo + ", " + item.bar);
}
Now, you need to make sure that you write JSP code in such way that exactly this valid HTML/JS code is generated (as you can verify by rightclick and View Source in webbrowser).
Provided that ${chart} is a List<Item> or Item[], one of most naive ways is using <c:forEach> to loop over it, printing the desired JS code output:
var chart = [<c:forEach items="${chart}" var="item" varStatus="loop">
{ foo: "${item.foo}", bar: "${item.bar}" }${loop.last ? '' : ','}
</c:forEach>];
In its simplest form, it should work fine. However, trouble starts once you get "special characters" as property values, such as " or even a newline. You'd need to escape it. Much better is to use an existing JSON library, such as Google Gson in order to convert a complex Java object, such as a List<Item> or Item[], to a valid JSON string. E.g. as follows in the servlet:
List<Item> chart = createItSomehow();
request.setAttribute("chart", new Gson().toJson(chart));
// ...
Then you can just do:
var chart = ${chart};