Reputation: 3588
I should call a javascript function from java.
I use a ScriptManager:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval(new java.io.FileReader("js/myjsfile.js"));
Invocable inv = (Invocable) engine;
Boolean val=(Boolean)inv.invokeFunction("check", value);
I obtain a java.io.FileNotFoundException.
My project uses the tomcat directory structure:
-java src
-WebContent
index.jsp
->js-> myjsfile.js
->jsp
->WEB-INF
->META-INF
How could I access to js/myjsfile.js from a java file?
EDIT I resolved with
String path = request.getServletContext().getRealPath("/js/myjsfile.js");
Upvotes: 0
Views: 365
Reputation: 11
You could use the absolute path to read the js file and The absolute path of "catalina.home" can be get from the System property.
Upvotes: 1