سؤال

I'm trying to get java and javascript to talk to each other. Ideally, I would want them to share objects, but it would be enough that a java-application calls a javascript function. I've tried Rhino but struggle a bit, because it doesn't seem able to call functions in a running js-engine (maybe it can I just couldn't figure out how?). Any tips on how to make this link happen? Performance is an issue but not extremely critical.

Basically; I have a web application that uses javascript to update the content of the page dynamically. The content of the page is created through java-code, so I need a way for the java-code to tell the javascript when something changes and what changes.

Thanks

LiveConnect seems to do the trick, but applet would be a security-leak. Would Nashorn in Java8 do the same as Rhino or will it be able to keep a running JVM and listen to calls?

هل كانت مفيدة؟

المحلول

There's no way to make the Java back end and JavaScript talk directly to each other the way you imply you want to do. The only way to make them communicate is through AJAX or WebSockets.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top