I have a list of strings on my server which I am trying to get to the client in the form of an array. The code I am attempting to use is the following:
Within the js
Once the JavaScript reaches the client, the server code has stopped executing. The server code does not execute "in parallel" with the client code.
You have to build the entire JavaScript initialization in Java and send it, complete and executable, to the client:
<%
StringBuffer values = new StringBuffer();
for (int i = 0; i < columns.size(); ++i) {
if (values.length() > 0) {
values.append(',');
}
values.append('"').append(columns.get(i)).append('"');
}
%>
That is just one way to do it, you can also build the output "on the fly" by embedding the server code inside the [
and ]
. I used this example to try to demonstrate the separation between building the string that comprises the client-side JavaScript and outputting that to the browser.