简体   繁体   English

p:fileUpload在哪里保存我的文件?

[英]Where does p:fileUpload save my file?

I have ap: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. 我的页面上有ap:fileUpload函数,每次上传文件时,我都无法在web.xml文件中指定的文件夹中找到它。

I have added the following jars to my library: primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar 我已将以下罐子添加到我的库中:primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar

Here is my web.xml file: 这是我的web.xml文件:

<?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:\Users\SomeUser\Documents\NetBeansProjects\System\Upload\</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>

I am using the following: PrimeFaces 3.2, JSF 2.0 and GlassFish 3.1.1 我使用以下:PrimeFaces 3.2,JSF 2.0和GlassFish 3.1.1

Any help will be appreciated. 任何帮助将不胜感激。 Thanks 谢谢

It stores it by default in the system default temp directory as identified by java.io.tmpdir system property. 它默认将其存储在系统默认临时目录中,由java.io.tmpdir系统属性标识。 You could use UploadedFile#getContents() or UploadedFile#getInputStream() to get the file contents and write it to the desired folder. 您可以使用UploadedFile#getContents()UploadedFile#getInputStream()来获取文件内容并将其写入所需的文件夹。 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: 把它放在文件上传过滤器的<filter>元素中:

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

Note that when you're running Windows, it will be relative to the disk from where the webserver is started. 请注意,当您运行Windows时,它将相对于启动Web服务器的磁盘。 So if it's C:\\ , then the above init param will actually resolve to C:\\path\\to\\uploads . 因此,如果它是C:\\ ,那么上面的init参数实际上将解析为C:\\path\\to\\uploads You should also make sure that this folder is already been prepared beforehand and thus exists and is writable. 您还应该确保此文件夹已经预先准备好,因此存在且可写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM