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