访问输入类型=“文件"来自 Java 小程序的完整路径 [英] Accessing input type="file" full path from a Java applet

查看:28
本文介绍了访问输入类型=“文件"来自 Java 小程序的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用 netscape.javascript JSObject API 从小程序访问 HTML DOM.但是,如果我查询 input type="file" 的值,在某些浏览器 (Opera) 上,我会得到所选文件的完整路径,但在其他浏览器(Firefox、Chrome)上,只有一个文件名没有路径.

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.

是否有可能通过 HTML input type="file" 找出从 Java 小程序中选择的文件的完整路径?

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?

我费心的原因:签名的小程序可以访问文件系统,浏览器的文件选择器比Java swing的好很多.

The reason why I bother: signed applets can access file system, and browsers' file selectors are a lot nicer than Java swing one.

推荐答案

你不能.您受到 HTML/JS(和浏览器)安全限制的限制.正式地, input type="file" 的值应该只返回文件名,而不是文件路径.然而,我很惊讶 Opera 返回了完整路径,即因为 MSIE 是我所知道的唯一一个这样做的人.

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.

但是既然您已经在运行小程序,为什么不直接使用它的功能呢?您可以使用 Swing 的 JFileChooser 选择一个文件,与 HTML input type="file" 完全一样.

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

这篇关于访问输入类型=“文件"来自 Java 小程序的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆