访问输入类型=“文件” Java 小程序的完整路径
可以使用 netscape.javascript JSObject API 从小程序访问 HTML DOM。 但是,如果我查询输入类型=“文件”的值,在某些浏览器(Opera)上我会得到所选文件的完整路径,但在其他浏览器(Firefox,Chrome)上只是一个没有路径的文件名 。
是否可以通过 HTML 输入 type="file" 找出从 Java 小程序中选择的文件的完整路径?
我之所以烦恼的原因是:签名的小程序可以访问文件系统,并且浏览器的文件选择器比 Java swing 好很多。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。您受到 HTML/JS(和浏览器)安全限制的限制。正式地,
input type="file"
的值应该只返回文件名,而不是文件路径。然而,令我惊讶的是 Opera 返回了完整路径,即因为 MSIE 是我所知道的唯一一个执行此操作的人。但是既然您已经在运行一个小程序,为什么不利用它的功能呢?您可以使用 Swing 的
JFileChooser
选择一个文件,就像使用 HTMLinput type="file"
所做的那样。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 HTMLinput type="file"
.