Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html MAC在Chrome&;中给我的路径为c:\fakepath;游猎。在FF中正常工作_Html_Jsf 2_Cross Browser_Filepath_Undefined Behavior - Fatal编程技术网

Html MAC在Chrome&;中给我的路径为c:\fakepath;游猎。在FF中正常工作

Html MAC在Chrome&;中给我的路径为c:\fakepath;游猎。在FF中正常工作,html,jsf-2,cross-browser,filepath,undefined-behavior,Html,Jsf 2,Cross Browser,Filepath,Undefined Behavior,下面是我在JSF2.0中的内容 <tr> <th width="19%" align="left"><h:outputLabel value="Photo" /></th> <th width="2%">:</th> <td width="19%"><h:inputText value="#{PersonalInformationDataBean.photo}" size="80"

下面是我在JSF2.0中的内容

<tr>
    <th width="19%" align="left"><h:outputLabel value="Photo" /></th>
    <th width="2%">:</th>
    <td width="19%"><h:inputText value="#{PersonalInformationDataBean.photo}" size="80" id="photo" readonly="true"/> 
    <input type="file" name="pathPhoto" onchange="alert('you changed me...'+window.document.patentForm.pathPhoto.value);window.document.patentForm.photo.value=window.document.patentForm.pathPhoto.value"/></td>
</tr>
这就是为什么,我很想得到所选文件的完整路径


想得到这个吗?

在web应用程序中,您不希望依赖于在服务器上查找文件。您最好将其存储在应用程序的根目录下,然后按如下方式检索:

ExternalContext external = FacesContext.getCurrentInstance().getExternalContext();
ServletContext servletContext = (ServletContext) external.getContext();
InputStream is = servletContext.getResourceAsStream("image.jpg");

但是理想情况下如果您使用的是JSF和Servlet 3.0容器,我建议您使用他在博客中写的文件上传,可以找到

如果您没有Servlet3.0,那么可以使用教科书中编写的文件上传示例。您可以从作者的站点下载源代码,它位于ch13目录中

当您使用上述任何组件提交表单时,您可以做任何您想做的事情,比如在action方法中保存到数据库


或者,如果您可以使用PrimeFaces之类的库,那么它们有一个很好的文件上载组件,您可以直接使用。

Firefox提供了真正的路径,这让您感到非常惊讶。你不能得到它,因为它是一个(小)安全风险时,你可以。你为什么想要完整的路径?@ReneGeuze:我想把路径存储在mysql数据中。我还想在mysql中上传这个文件……我读到了,但是拥有完整路径的真正用途是什么?要知道用户是从c驱动器还是d驱动器上传?我这么问是因为有人可能会给出一个更可靠的替代方案。@ReneGeuze:我更新了这个问题。请让我知道你的观点。你说“按钮
选择文件”
“代码中没有“
选择文件”
”。
ExternalContext external = FacesContext.getCurrentInstance().getExternalContext();
ServletContext servletContext = (ServletContext) external.getContext();
InputStream is = servletContext.getResourceAsStream("image.jpg");