package com.fhs.main;
import java.io.File;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class TestExeJs {
/**
* @param args
* @throws ScriptException
* @throws NoSuchMethodException
*/
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
// TODO Auto-generated method stub
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
String script = "function hello(name) { return 'Hello,' + name;}";
engine.eval(script);
Invocable inv = (Invocable) engine;
String res = (String)inv.invokeFunction("hello", "疯汉三" );
System.out.println("res:"+res);
}
}
java调用 javascript
最新推荐文章于 2021-07-29 11:23:00 发布