Forums Register Login

Sharing of variables

+Pie Number of slices to send: Send
Can Jsp and javascript share variables???
+Pie Number of slices to send: Send
No. JSPs execute on the server, while JavaScript runs on the client.
+Pie Number of slices to send: Send
If the jsp variables are of primitive type and once the page is loaded the values are not goin to change,
then you can forward the variables to the javascript.
Example.
"& lt;"html>
"& lt;"head>
"& lt;"script language="javascript">
var jspvariable;
function test(tempVariable){
jspVariable = tempVariable;
alert(jspVariable);
}

"& lt;"/script>
"& lt;"/head>
"& lt;"body>
"& lt;"%
int jspVariable = 2;
%>
wwindow. oon load = function(){
test("& lt;"%=jspVariable%>){
}

"& lt;"/body>
"& lt;"/html>

after the page is loaded you can use the jspVariable in the jsp. it is a global variable in the Javascript scope
+Pie Number of slices to send: Send
But that is far from "sharing" the variable. The JSP can create whatever JavaScript it wants, but they cannot interact.

Please read this article for more info.
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1021 times.
Similar Threads
Runtime.getRuntime() help plzzzzzzzz
Why Java ?
Variables in Java
Variables
Opening .bat files from ant
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:47:01.