• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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???
 
Rancher
Posts: 43081
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: 67754
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic