Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Invoke java method from JavaScript (not applet!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Invoke java method from JavaScript (not applet!)" Watch "Invoke java method from JavaScript (not applet!)" New topic
Author

Invoke java method from JavaScript (not applet!)

Vlad Golodov
Ranch Hand

Joined: Jul 05, 2004
Posts: 50
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?


SCJP, SCJWSD prepairing<br /><a href="http://www.vladgolodov.com" target="_blank" rel="nofollow">http://www.vladgolodov.com</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I think you are going to have a JavaScript security problem on the browser side. Using JS to load stuff from different IP addresses was determined to be a gaping security hole many years ago. The same restrictions apply to applets trying to open connections to different addresses.

You can have a server-side function effectively relay the query and send the results back to JS.

Bill
Vlad Golodov
Ranch Hand

Joined: Jul 05, 2004
Posts: 50
Thanks for the answer

It's not possible to execute something on user's site. I can put only small JS code into his page.

Problem is that i need to show two types of buttons on site. One type will be shown if statement from my server returns true, another if false.

It's possible to write a jsp or servlet that will return the result on my site. Then from JS i can execute URL and get the text of document like variable. But i don't know how to execute url and get this text in JS. Maybe it's not possible too. I have searched about it, but found nothing helpfull.
[ July 06, 2004: Message edited by: Vlad Golodov ]
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
just put an iframe with a fixed source to your JSP that will display the correct buttons. I see no other way.
[ July 09, 2004: Message edited by: Anton Golovin ]

Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoke java method from JavaScript (not applet!)