最近要操作js,先把搜集到的代码进行整理:
//实例化js引擎
ScriptEngineManager smg = new ScriptEngineManager();
ScriptEngine engine = smg.getEngineByName("JavaScript");
//获取本地js文件
FileReader reader1 = new FileReader(jsFileName); // 执行指定脚本
engine.eval(reader1);
if(engine instanceof Invocable) {
Invocable invoke = (Invocable)engine;
// 调用pgvSetPvidCookies方法,没有传参数
pgv_Pvid = invoke.invokeFunction("pgvSetPvidCookies").toString()+";";
System.out.println(pgv_Pvid);
}
//关闭流