I have a JSP page called index.jsp. I have a Java variable called totalCount inside this page :
Now I want to use this variable in Javascript section to generate a chart:
How can I pass this Java variable inside ? Thanks.
解决方案
Just assign the value to your Javascript variable.
var count = '';
But using scriptlets been highly discouraged and shift to JSTL as soon as possible.
As others pointed out, do not create unnecessary hidden elements on DOM. If you really want to use this variable across files declare this variable on top. Even before script includes, so that it avail across all the files.
Example:
var count = '';