Skip to content Skip to sidebar Skip to footer

Can Anyone Give A Complete Example Of How To Call A Js Using Java File?

My code is like SJCL.js function encrypt(data, key){ ...... } abcd.java public String callJavascript(String data,String key) { // i want to call the encrypt method here wi

Solution 1:

I'm sure you checked this one: http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html

What you are probably looking for is under the 'Invoking Script Functions and Methods' (an example to call your 'crypt()' from java)

ok, just a thought on feasibility though: you can always pass a 'java.io.Reader' pointing your js file, to engine.eval() but if this is a web application then you're heading for disaster. You'd be better off keeping the encrypt() functionality from sjcl.js in a separate file (say encrypt.js), including this file into sjcl.js.

You can then read encrypt.js once and cache its contents in a static String in your java class. You can then pass this string to engine.eval() without I/O performance impact.

Solution 2:

I think following articles will help you:

EDIT:

Rhino:

I think reading the documentation will help you to implement this.

There are also some other options:

Post a Comment for "Can Anyone Give A Complete Example Of How To Call A Js Using Java File?"