javascript - Access a js file from java in a project with tomcat directory structure (java.io.FileNotFoundException) -


i should call javascript function java.

i use 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 java.io.filenotfoundexception.

my project uses tomcat directory structure:

-java src -webcontent  index.jsp  ->js-> myjsfile.js  ->jsp  ->web-inf  ->meta-inf 

how access js/myjsfile.js java file?

edit resolved

 string path = request.getservletcontext().getrealpath("/js/myjsfile.js"); 

you use absolute path read js file , absolute path of "catalina.home" can system property.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -