在JSF中获取所选文件的完整路径 [英] Get full path of selected file in JSF

查看:41
本文介绍了在JSF中获取所选文件的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个JSF按钮,该按钮允许用户浏览并选择特定文件,然后我需要我的程序来检索文件的完整路径.

I need a JSF button which allows user to browse and select a particular file, then I need my program to retrieve full path of the file.

当用户从服务器本身运行客户端部分时(即浏览到托管该Web应用程序的同一服务器中的文件),此功能是必需的.如果用户从另一台计算机发送请求,则上传文件就足够了.

This functionality is required when user runs the client portion from the server itself (i.e. browses to the file in the same server which hosts the web app). If the user sends request from another machine, then uploading the file is enough.

目前,我正在使用h:inputFile标记.

For now, I am using h:inputFile tag.

 <h:inputFile id="file" value="#{TrainingDirectoryBean.file}"></h:inputFile>

我的bean:TrainingDirectoryBean具有以下属性

My bean : TrainingDirectoryBean has the following property

protected Part file;

但是我无法从中得到完整的路径.解决办法是什么?

But I can't get full path from it. What is the solution?

推荐答案

JSF <h:inputFile>组件生成HTML <input type="file">元素,该元素只能正式发送文件内容以及唯一的文件名—.尽管某些浏览器,特别是Redmond的一些团队开发的浏览器,由于安全漏洞,也会发送完整的文件路径以及文件名;因此,当然不应依赖它,因为它可能会在将来的版本中修复和删除.

The JSF <h:inputFile> component generates a HTML <input type="file"> element which is officially only capable of sending the file content along with the sole file name — although certain browsers, particularly the one developed by some team in Redmond, also send the full file path along with the file name due to a security bug; which should thus certainly not be relied upon as it may be fixed and removed in future versions.

用HTML术语来说,不存在任何允许最终用户从其本地磁盘文件系统中选择完整文件路径并将其完整(没有相关文件内容)发送到服务器的元素.由于在这个问题中JSF只是一个HTML代码生产者,因此在JSF中也不可能.

In HTML terms, there does not exist any element which allows the enduser to select a full file path from its local disk file system and send it in its entirety (without the associated file content) to the server. Since JSF is in the context of this question merely a HTML code producer, it isn't possible in JSF either.

考虑创建基于 Swing .oracle.com/javase/tutorial/deployment/applet/"rel =" nofollow> Applet ,您通常将其嵌入HTML页面(或JSF页面)中,这取决于您解释事物的方式). Swing JFileChooser 具有以下功能:选择本地磁盘文件系统位置并获取完整路径的任务.您可以依次通过 URLConnection 发送到服务器(不要忘记对applet签名,以免打扰和担心最终用户可能会产生的安全警告).

Consider creating a Swing based Applet which you in turn embed the usual way in your HTML page (or JSF page, depending on the perspective how you interpret things). The Swing JFileChooser is capable of the task of selecting a local disk file system location and obtaining the full path. You can in turn send this information via URLConnection to the server (don't forget to sign the applet to avoid bothering and worrying the enduser about the security warnings it may produce).

这篇关于在JSF中获取所选文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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