Generally speaking, you don't, at least not directly.
There are (at least) four options:
Option 1: Render your JavaScript in the JSP file, use normal S1 JSP methods to inject it into the JS. It will need to be properly JavaScript-escaped.
Option 2: Render your JavaScript through the JSP processor, e.g., add *.js
to the list of files that need JSP processing. IMO not preferred, but it's an option. Other frameworks do this (like Rails ERb JS templates) but it's a little counter-inuitive, and can make finding functionality incrementally more difficult.
Option 3: Retrieve the value later via Ajax. Likely also not preferred since there's a mechanism you can use to avoid it. If there's a lot of other Ajax on the page it might not be as bad, but requires a new or modified JSON endpoint etc.
Option 4: Render the data into the JSP using normal JSP methods. The JS, which in general should be externalized to a .js
file anyway, can refer to this data only after the page is fully reader, e.g., $(function () { ...data is ready... }
.
You'd probably want to namespace/modularize the data as well, but that's a general good practice anyway.