Java/JSP runs in webserver at the server machine and produces HTML/CSS/JS code. Server machine sends HTML/CSS/JS code to client machine. HTML/CSS/JS runs in webbrowser at client machine. Rightclick page and view source, you don't see any Java/JSP code.
JSP is a view technology which provides a template to write HTML/CSS/JS in and the ability to interact with backend Java data using taglibs/EL to control page flow and access data.
Whenever you want to let JavaScript access Java/JSP variables, all you need to do is to just write a Java variable as if it is a JavaScript variable.
<script>var foo = '${bean.foo}';</script>
Is an excellent example. Note that those quotes are required for JavaScript itself, not for JSP/EL. Imagine that ${bean.foo}
returns bar
, then the generated HTML/CSS/JS page which arrived at the client side would end up looking like:
<script>var foo = 'bar';</script>
Whenever you want to let Java/JSP access JavaScript variables, all you need to do is to let JavaScript fire a (XML)HTTP request. More background info and examples can be found in this article.