Java SE6中添加了脚本语言API,可通过java进行灵活的操作脚本语言。以下是示例代码: //操作属性 &#9; public static void attributeInBindings() throws ScriptException { &#9;&#9; ScriptEngine engine = new ...<br>Java SE6中添加了脚本语言API,可通过java进行灵活的操作脚本语言。以下是示例代码:<br>//操作属性&#9; public static void attributeInBindings() throws ScriptException {&#9;&#9; ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");&#9;&#9; ScriptContext context = engine.getContext();&#9;&#9; context.setAttribute("name", "Alex", ScriptContext.GLOBAL_SCOPE);&#9;&#9; engine.eval("println(name);");//输出Alex&#9; }//调用方法&#9; public static void invokeFunction() throws ScriptException, NoSuchMethodException{&#9;&#9; ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");&#9;&#9; String scriptText = "function greet(name){println('hello,'+name);}";&#9;&#9; engine.eval(scriptText);&#9;&#9; Invocable invocable = (Invocable)engine;&#9;&#9; invocable.invokeFunction("greet", "wenxin");&#9; }//调用脚本中对象成员方法&#9; public static void inv