views:

740

answers:

1

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 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.

+1  A: 

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".

BalusC
- JFileChooser is ugly.- I wouldn't be able to send the file I choose with JFileChooser by submitting the HTML form.That's a pity.
alamar
You can customize Swing look'n'feel: http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/
BalusC