• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP/Java/JavaScript Communication

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
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
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.
 
What are you doing? You are supposed to be reading this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic