我在页面上有一个p:fileUpload函数,每次上传一个文件,我都无法在我的web.xml文件中指定的文件夹中找到它。
我已经将下面的jar文件添加到我的库中:primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar
以下是我的web.xml文件: $ b
<?xml version =1.0encoding =UTF-8?> < web-app xmlns =java.sun/xml/ns/javaee xmlns:xsi =www.w3/2001/XMLSchema -instance xsi:schemaLocation =java.sun/xml/ns/javaee java.sun/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> <参数值> 1000000< /参数值> < / 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> <错误页面> <错误代码> 404< /错误代码> < 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
任何帮助将不胜感激。谢谢
解决方案它默认将其存储在系统默认的临时目录中,由 java.io标识。 tmpdir 系统属性。您可以使用 UploadedFile#getContents()或 UploadedFile#getInputStream()来获取文件内容并将其写入所需文件夹。但是,您也可以通过过滤器的初始化参数更改默认的上传位置。
将其放在文件上传过滤器的< filter> 元素中:
< init-param> < param-name> uploadDirectory< / param-name> < param-value> / path / to / uploads< / param-value> < / init-param>请注意,当您运行Windows时,它将相对于Web服务器所在的磁盘开始。所以如果它是 C:\ ,那么上面的init参数实际上会解析为 C:\path\to\uploads 。你也应该确保这个文件夹已经预先准备好了,因此存在并且是可写的。
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.
I have added the following jars to my library: primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="java.sun/xml/ns/javaee" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/javaee java.sun/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
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. 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>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\to\uploads. You should also make sure that this folder is already been prepared beforehand and thus exists and is writable.
更多推荐
p:fileUpload在哪里保存我的文件?
发布评论