I need to creata an array in javascript, elements for the array should come from server side.
For this what i did was,
In servlet,
String[] valuesArray = {"val1","val2","val3"};
request.setAttribute("valuesArray",valuesArray);
In Jsp/javaScript:
var arrayObj = new Array(${'valuesArray'});
but,this is not working..
Ultimately, arrayObj should contain {“val1″,”val2″,”val3”} as elements.
Can someone please suggest where i have gone wrong or let me know how to handle this requirement?
Thanks in advance.
Unfortunately I havn’t found a simpler way to do it. This is how i always did –
Pay close attention to all quotes and scriplet tag.
You can also use jsp for loop or c:for instead of scriplet here.