Java 中调用JavaScript

JDK1.6中加入了对JavaScipte脚本的调用方法,代码如下

 

public static void main(String[] args) throws Exception {
		ScriptEngineManager mgr = new ScriptEngineManager();
		ScriptEngine engine = mgr.getEngineByName("JavaScript");
		String js = "23+3*32/2-65";
		Object eval = engine.eval(js);
		System.out.println(eval);
		
		System.out.println(23+3*32/2-65);
	}

 

你可能感兴趣的:(JavaScript,java,脚本,idea)