可能重複:
How can I run JavaScript code at server side Java code?如何在Java編程運行JavaScript
是否有可能運行的JavaScript一個Java平臺
可能重複:
How can I run JavaScript code at server side Java code?如何在Java編程運行JavaScript
是否有可能運行的JavaScript一個Java平臺
請參閱javax.script
。這是Java SE的一部分。用法舉例
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("print('Hello, World')");
多看這裏http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html
可以請你澄清我如何使用您的解決方案爲HTTPS: //stackoverflow.com/questions/47411742/how-to-trigger-google-tag-manager-script-from-java-code? – vikramvi
該文檔[爲Java 8重新編寫](https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html)。 –
你可以做到這裏面使用ScriptEngineManager(javax.script
包)。閱讀本文:http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/
[犀牛(https://developer.mozilla.org/de/docs/Rhino) – clentfort