Failed to access Java code from XUL/JavaScript -
this java file :
import java.io.file; import java.lang.string; public class listfiles { public static void main(string[] args) { // directory path here string path = "d:/xmlfiles/"; string files; file folder = new file(path); file[] listoffiles = folder.listfiles(); (int = 0; < listoffiles.length; i++) { if (listoffiles[i].isfile()) { files = listoffiles[i].getname(); system.out.println(files); } } } }
this js file :
function display(){ el = document.getelementbyid("text"); el.addeventlistener("oncommand", display, true); //loading encryption class //alert('hffffi'); var myclass = cl.loadclass('listfiles'); // use same loader above var myobj = myclass.newinstance(); // pass whatever arguments need (they'll auto-converted java form, taking account liveconnect conversion rules) var files = myobj.string; alert('karthik works'+files); document.getelementbyid("text").value=files; }
explanation : i'm trying ouptput string of java js. i'm able connect java js using live connect in xul firefox. problem right now, how can display output of java in js file.
thanks guys.
if understand correctly, var files = myobj.string;
supposed return output of java program?!
i dunno liveconnect, i'd more expect listfiles
class have method returns list. read local variable (and main()
not called automatically in liveconnect setup anyway).
so how like:
public class listfiles { public: string getfiles() { string result = ""; // [iterate on files , add names result] return result; } }
and in js code:
var files = myobj.getfiles();
instead of
var files = myobj.string;
Comments
Post a Comment