日期:2014-05-17 浏览次数:20686 次
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = "test.js"; // 读取js文件
FileReader reader = new FileReader(jsFileName); // 执行指定脚本
engine.eval(reader);
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "g" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:232)