I have forwarded an array userName[][] from a servlet to a JSP. I can access the array elements like ${userName[2][3]}, but i cant iterate through the array using a variable. e.g. ${userName[i][j]} or ${userName[<%=i>][<%=j>]} dont work.
also, should i declare my index variables as var(JS) as my code also uses JS to plot a graph from the array,or do I need to use JSTL? I’m a complete newbie to JSP
Here’s how you iterate through an array in JSTL (Note that I pluralized your userName variable, since it’s an array):
Since you array is an array of arrays, you can nest two iterations:
Note that JavaScript executes at client-side, whereas the JSP is executed at server-side. When JS code executes, it doesn’t have access to your server-side Java array. If you need to access the contents of the Java array at client-side, you should serialize it with JSON, and parse the resulting JSON String in JavaScript.