标签:jsf engine 传参 eva print 读取 类型 catch exists
1、request.getSession().getServletContext().getRealPath("") 获取前端文件的根路径
2、
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = request.getSession().getServletContext().getRealPath("")+ "\\web\\des.js"; // 读取js文件
File f = new File(jsFileName);
if (f.exists()) {
System.out.println("文件存在");
} else {
System.out.println("没有找对文件的路径");
}
FileReader reader;
try {
reader = new FileReader(jsFileName);
engine.eval(reader);
if (engine instanceof Invocable) {
Invocable invoke = (Invocable) engine; // 调用strEnc方法,并传参
String c = (String) invoke.invokeFunction("strEnc", "123456","aa", "bb", "cc");//根据返回的类型决定是否为String类型
System.out.println("c = " + c);
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
} // 执行指定脚本
标签:jsf engine 传参 eva print 读取 类型 catch exists
原文地址:https://www.cnblogs.com/ffzzcommsoft/p/9117700.html