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

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

问题描述

可以使用netscape.javascript JSObject API从小程序访问HTML DOM。
但是,如果我查询输入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输入类型=文件找出其中选择的文件的完整路径来自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.

但是,当你已经在运行一个applet,你为什么不使用它的功能?您可以使用 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天全站免登陆