• 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

Invoke java method from JavaScript (not applet!)

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to invoke a simple method from users site.
For example, it could be

public class Test{
public Test(){
}

public String getString(String parameter){
return "String";
}
}

From JS i need to getString from Test. My class will work with Oracle and will be located on a different ip-address.

Is it possible without Applet?
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To invoke a java method from javascript - have a look at http://www.rgagnon.com/howto.html
Then click on java and go to Javascript interaction.

Cheers,
Rachel
 
Vlad Golodov
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the good resourse, but i can't use applets in my task. Even if i would use applets, they wouldn't permit to make a call from other domain

Maybe there are more possibilities how to get variable from java to JS?

I have to check

if(variable == true)
1
else
2

And i have to take this variable from java located on different site. On client site can use only small JS code.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using JSP, you might be able to do it with an expression. I did this once with ASP. For example, if your javascript code needs to use a JSP variable:

function myJsFunction () {
var jsVar = <%= jspVar %>;
}

The jspVar could be a value returned from a Java method. I haven't tried this in JSP, but it did work in ASP.
 
reply
    Bookmark Topic Watch Topic
  • New Topic