Posts

Showing posts with the label Parameter Passing

Access Java / Servlet / JSP / JSTL / EL Variables In JavaScript

Answer : You need to realize that Java/JSP is merely a HTML/CSS/JS code producer. So all you need to do is to just let JSP print the Java variable as if it is a JavaScript variable and that the generated HTML/JS code output is syntactically valid. Provided that the Java variable is available in the EL scope by ${foo} , here are several examples how to print it: <script>var foo = '${foo}';</script> <script>someFunction('${foo}');</script> <div onclick="someFunction('${foo}')">...</div> Imagine that the Java variable has the value "bar" , then JSP will ultimately generate this HTML which you can verify by rightclick, View Source in the webbrowser: <script>var foo = 'bar';</script> <script>someFunction('bar');</script> <div onclick="someFunction('bar')">...</div> Do note that those singlequotes are thus mandatory in ord...