1, Request.getsession (). Getservletcontext (). Getrealpath ("") gets the root path of the front-end file
2.
Scriptenginemanager manager = new Scriptenginemanager ();
ScriptEngine engine = Manager.getenginebyname ("javascript");
String jsfilename = Request.getsession (). Getservletcontext (). Getrealpath ("") + "\\web\\des.js"; Read JS file
File F = new file (jsfilename);
if (f.exists ()) {
System.out.println ("file exists");
} else {
SYSTEM.OUT.PRINTLN ("No path to file found");
}
FileReader reader;
try {
reader = new FileReader (jsfilename);
Engine.eval (reader);
if (engine instanceof invocable) {
invocable invoke = (invocable) engine; Call the Strenc method and pass the argument
String c = (string) invoke.invokefunction ("Strenc", "123456", "AA", "BB", "CC");//is a String type depending on the type returned
System.out.println ("c =" + C);
}
Reader.close ();
} catch (Exception e) {
E.printstacktrace ();
}//execute the specified script
Java path query and run JS file method in background