2013-01-14 41 views

回答

47

請參閱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

+0

可以請你澄清我如何使用您的解決方案爲HTTPS: //stackoverflow.com/questions/47411742/how-to-trigger-google-tag-manager-script-from-java-code? – vikramvi

+0

該文檔[爲Java 8重新編寫](https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html)。 –