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

Can Javascript acces the variables defined in JSP.  RSS feed

 
Anil Kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible the use the variable defined by JSP
<%! int i =0> in java script.
If yes then How, Since we need document.form.field_name.value to play with fields of the HTML form.
I would appriocate if someone could send me sample code.
Thanks in advance.

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, if you declare your JSP variable like that (with the exclamation mark) then chances are your code won't be thread safe. You might want to read this
The basic answer to you question is "No, you can't". JSP variable exist on the server and Javascript exists entirely on the browser. The only overlap is that the server outputs a bunch of HTML that gets sent to the client, so if you include the value of the variable in here, it can be sent to the browser...

So even thought they can't share variables, they can share values.
Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!