permaculture playing cards
The moose likes JSP and the fly likes JSP/Java/JavaScript Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP/Java/JavaScript Communication" Watch "JSP/Java/JavaScript Communication" New topic

JSP/Java/JavaScript Communication

Steve Watson
Ranch Hand

Joined: Apr 08, 2003
Posts: 38
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

Joined: Jan 10, 2002
Posts: 63838

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.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP/Java/JavaScript Communication
It's not a secret anymore!