It is possible to access HTML DOM from an applet using netscape.javascript JSObject API. However, if I query a value of a input type="file", on some browsers (Opera) I get a full path to a selected file, but on other browsers (Firefox, Chrome) just a file name without path.
Is it possible, having an HTML input type="file", to figure out the full path to the file selected in it from 开发者_Python百科a Java applet?
The reason why I bother: signed applets can access file system, and browsers' file selectors are a lot nicer than Java swing one.
You cannot. You're restricted by HTML/JS (and browser) security limitations. Officially, the value of input type="file"
should only return the filename, never the filepath. I am however surprised that Opera returns the full path, namely because MSIE was the only one I knew of who did it.
But as you're already running an applet, why don't you just make use of its capabilities? You can use Swing's JFileChooser
to select a file, exactly as you can do with HTML input type="file"
.
精彩评论