Calling Java method from JavaScript using ScriptEngine - Stack Overflow

I'm using ScriptEngine, running JavaScript.I want the JavaScript script to be able to call myFunct

I'm using ScriptEngine, running JavaScript.

I want the JavaScript script to be able to call myFunction(), where myFunction() is a method inside a given class of mine.

I know it's possible to use importPackage for standard Java stuff, what about my own methods?

Please advise :)

I'm using ScriptEngine, running JavaScript.

I want the JavaScript script to be able to call myFunction(), where myFunction() is a method inside a given class of mine.

I know it's possible to use importPackage for standard Java stuff, what about my own methods?

Please advise :)

Share Improve this question asked Nov 3, 2010 at 18:07 Richard TaylorRichard Taylor 2,7522 gold badges25 silver badges46 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

According to this, when you do

importPackage(java.awt)

in a script, that's actually a shortcut for a built-in global variable called Packages -- "java.awt" is actually a shortcut for "Packages.java.awt". So you might try and see whether, if you create your own package called ".mypackage.hello", the scripting engine can access Packages..mypackage.hello. I haven't been able to find any documentation on that, but it's worth trying.

Not sure what you are actually trying to do but typically, you would make an HTTP Request from your JavaScript using XHR to talk to backend service exposed through HTTP.

You will have to make your Java Class function accessible through a servlet/HTTP interface.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745361957a4624401.html

相关推荐

  • Calling Java method from JavaScript using ScriptEngine - Stack Overflow

    I'm using ScriptEngine, running JavaScript.I want the JavaScript script to be able to call myFunct

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信