• 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

How does Java access JavaScript Values

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

we have a requirement to capture mouse coordinates that is x and Y position and pass these values
to a Java Method

Now I have capured x and y corodinate values on a Mouse click on a web page , which is written in JavaScript.

Now how can i pass these captured values ( X and Y ) to a Java Method .

Please tell me , how can i do this ??

Thanks in advance .



 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:capture mouse coordinates that is x and Y position and pass these values
to a Java Method


Where is this Java method, in an applet or at server side servlet method?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sagar for responding . The Java Method is in the same Jsp .
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote: The Java Method is in the same Jsp .


OK, that's mean method is in Scriptlet and when JSP page got request, at server side this scriptlet gets compiled, executed and its result is shown in JSP page. And Javascript is something for browser action, for client side, there is no existence of "Java Method" on client side html/jsp page.

So, you can't do this. Better try to implement the same Java Method logic in JavaScript
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Better try to implement the same Java Method logic in JavaScript



I am tying to pass this x and Y values to the MapViewer class .

This MapViewer class is from Oacle .

The logic is like this



Here x and y are of coordinates obtained from a Mousec click .

so please tell me is there any alternative to do this .
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simplified answer is: in order to "call Java" from JavaScript you either need to submit a form or make an Ajax request.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:

Better try to implement the same Java Method logic in JavaScript



Here x and y are of coordinates obtained from a Mousec click .
so please tell me is there any alternative to do this .


As suggested by David, try AJAX.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dead Lines are very tight and now can't start with AJAX .

I am thinking of this way ,please suggest will this work or not.

Inside my JavaScript function , i will send the captured x and Y coordinates to a different JSP say SecondJsp. and inside from my firstjsp i will include the second jsp using jsp:include with params and extract those values . Is this okay ??



 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:Dead Lines are very tight and now can't start with AJAX .


AJAX need half days dedication to learn and implement, as far as your specific need is concerned. Here is the basic for AJAX. [JS FAQ has good list for AJAX resources]

Ravi Pavan wrote:Inside my JavaScript function , i will send the captured x and Y coordinates to a different JSP say SecondJsp. and inside from my firstjsp i will include the second jsp using jsp:include with params and extract those values . Is this okay ??


This is something, I called as explicit AJAX. If your client/manager is happy with that kind of web experience, no problem, go ahead !!
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear locked my Thread assuming it the same question

https://coderanch.com/t/449040/HTML-JavaScript/Upon-right-click-needed-java

Please refer to this and give me suggestions .


Need to do it .
 
Sheriff
Posts: 67747
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
Same answer. You either need to submit a form, reload with a new page, or use Ajax.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AJAX would be right optinon. at first it looks difficult.. but its easy .

learn AJAX from www.w3schools.com.
 
Bear Bibeault
Sheriff
Posts: 67747
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
Ajax can be very easy, especially with the assist of a library. In jQuery it's one line of code:
 
What does a metric clock look like? I bet it is nothing like 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