在java中执行javascript脚本有什么意义?实际项目中有何应用?难道是实现类似于规则引擎之类的么?
我想到的意义是,可以把运算规则放在js文件中,这样就无需编译即可修改计算规则,谁来帮俺再补充一下还有其它作用么?这是代码:ScriptEngineManagermanag...
我想到的意义是,可以把运算规则放在js文件中,这样就无需编译即可修改计算规则,谁来帮俺再补充一下还有其它作用么?
这是代码:
ScriptEngineManager manager =new ScriptEngineManager();
ScriptEngine engine =manager.getEngineByName("javascript");
engine.eval("var a=3; var b=4;println (a+b);function aa(){ return \"abcdef\"; };function bb(a,b){ return a+b; };");
//engine.eval(new FileReader(new File("G:\\MyEclipse9Workspace\\Test\\src\\test\\a.js")));
Invocable in =(Invocable)engine;
Object returnO = in.invokeFunction("aa");
Object returnO2 = in.invokeFunction("bb", "fuck","b"); 展开
这是代码:
ScriptEngineManager manager =new ScriptEngineManager();
ScriptEngine engine =manager.getEngineByName("javascript");
engine.eval("var a=3; var b=4;println (a+b);function aa(){ return \"abcdef\"; };function bb(a,b){ return a+b; };");
//engine.eval(new FileReader(new File("G:\\MyEclipse9Workspace\\Test\\src\\test\\a.js")));
Invocable in =(Invocable)engine;
Object returnO = in.invokeFunction("aa");
Object returnO2 = in.invokeFunction("bb", "fuck","b"); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询