p:fileUpload 在哪里保存我的文件? [英] Where does p:fileUpload save my file?

查看:21
本文介绍了p:fileUpload 在哪里保存我的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个 p:fileUpload 函数,每次上传文件时,我似乎都无法在 web.xml 文件中指定的文件夹中找到它.

I have a p:fileUpload function on my page and every time I upload a file I cannot seem to find it in the folder specified in my web.xml file.

我已将以下 jars 添加到我的库中:primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar

I have added the following jars to my library: primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar

这是我的 web.xml 文件:

Here is my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

    <filter> 
        <filter-name>PrimeFaces FileUpload Filter</filter-name> 
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> 
    <init-param> 
        <param-name>uploadDirectory</param-name> 
        <param-value>C:UsersSomeUserDocumentsNetBeansProjectsSystemUpload</param-value> 
    </init-param> 
    <init-param> 
        <param-name>thresholdSize</param-name> 
        <param-value>1000000</param-value> 
    </init-param> 
    </filter>

    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <error-page>
        <error-code>404</error-code>
        <location>/404.jsf</location>
    </error-page>

    <context-param>  
    <param-name>primefaces.THEME</param-name>  
    <param-value>aristo</param-value>  
</context-param>  

</web-app>

我正在使用以下内容:PrimeFaces 3.2、JSF 2.0 和 GlassFish 3.1.1

I am using the following: PrimeFaces 3.2, JSF 2.0 and GlassFish 3.1.1

任何帮助将不胜感激.谢谢

Any help will be appreciated. Thanks

推荐答案

它默认将其存储在由 java.io.tmpdir 系统属性标识的系统默认临时目录中.您可以使用 UploadedFile#getContents()UploadedFile#getInputStream() 来获取文件内容并将其写入所需的文件夹.但是您也可以通过过滤器的初始化参数更改默认上传位置.

It stores it by default in the system default temp directory as identified by java.io.tmpdir system property. You could use UploadedFile#getContents() or UploadedFile#getInputStream() to get the file contents and write it to the desired folder. But you can also change the default upload location by an initialization parameter of the filter.

把它放在文件上传过滤器的元素中:

Put this inside the <filter> element of the file upload filter:

<init-param>
    <param-name>uploadDirectory</param-name>
    <param-value>/path/to/uploads</param-value>
</init-param>

请注意,当您运行 Windows 时,它将与启动网络服务器的磁盘相关.因此,如果它是 C:,那么上面的 init 参数实际上将解析为 C:path ouploads.您还应该确保此文件夹已预先准备好,因此存在且可写.

Note that when you're running Windows, it will be relative to the disk from where the webserver is started. So if it's C:, then the above init param will actually resolve to C:path ouploads. You should also make sure that this folder is already been prepared beforehand and thus exists and is writable.

这篇关于p:fileUpload 在哪里保存我的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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