This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP/Java/JavaScript Communication

 
Steve Watson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JavaScript function that includes Java code that needs to use varables from the JavaScript.


As you can see I have the following problems:

1. Giving a unique name to each instance of the Launcher class.
2. Passing the JavaScript "control" variable to the Java setId() method.
3. Passing "theForm.elements[i]" to the setTextComponentName() and setCallBack() methods where i is the iterator in the JavaScript loop.

Thanks for any help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't be done. That's not the way things work.

All of the code in your JSP executes on the server in order to compose a plain-old vanilla HTML/Javascript page to send to the browser. Once it gets there, your JSP is long gone and reclaimed (a simplificiation, but close enough for now).

So by the time your Javascript function finally gets around to executing, the Java is not there -- it executed long ago in order to render the page. Take a look at the results of a View Source to see what's being sent to the browser.

The only interaction possible between the client (your Javascript) and the server (your Java) is through the normal request/response HTTP cycle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic