• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Sharing of variables

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can Jsp and javascript share variables???
 
Master Rancher
Posts: 43045
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. JSPs execute on the server, while JavaScript runs on the client.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67694
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic