admin管理员组文章数量:1426666
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 badges2 Answers
Reset to default 6According 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.
本文标签: Calling Java method from JavaScript using ScriptEngineStack Overflow
版权声明:本文标题:Calling Java method from JavaScript using ScriptEngine - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745361957a2655336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论