Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sharing of variables  RSS feed

 
Adinath Shirsath
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Jsp and javascript share variables???
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. JSPs execute on the server, while JavaScript runs on the client.
 
Deepal Udeshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!