Download file in JSF networks

I am trying to upload a file with a simple form, but it just returns to the same page all the time. To find an error or something wrong, I just want to write the name of the downloaded file in the output. As soon as I can get the file name, I think I can handle how to handle the whole file. So this is my code:

<h:form enctype="multipart/form-data"> <h:outputText value="Argazkia: "/> <p:fileUpload value="#{jokoBerriaController.file}" mode="simple"/> <p:commandButton value="Bidali" ajax="false" actionListener="#{jokoBerriaController.upload()}"/> </h:form> 

Controller:

 import javax.faces.bean.ManagedBean; import org.primefaces.model.UploadedFile; @ManagedBean public class jokoBerriaController { public static UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; } public void upload() { System.out.println("file " + file.getFileName()); } } 

I added

 <filter> <filter-name>PrimeFaces FileUpload Filter</filter-name> <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> </filter> <filter-mapping> <filter-name>PrimeFaces FileUpload Filter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> 

in my web.xml file, but I did not add commons-io and commons-fileupload libraries. I read that I need to put the following code in my pom.xml file, but I can not find this file.

 <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.4</version> </dependency> 

Thank you for your help.

PD: Sorry for my English.

+1
java file-upload jsf primefaces
source share
4 answers

If you cannot find pom.xml, you do not create the application using maven and therefore you can simply copy the downloaded jar files to the WEB-INF/lib folder. Download commons-fileupload-1.2.2.jar and commons-io-1.4 and add it to this folder.

+1
source share

This post was really helpful .

You need to pay attention to all the details. All dependencies must be included in WEB-INF / lib, and the servlet filter in web.xml must be declared correctly.

I had similar problems, and I got his job, following the advice in this post.

+1
source share

You have added:

 <filter> <filter-name>PrimeFaces FileUpload Filter</filter-name> <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> </filter> <filter-mapping> <filter-name>PrimeFaces FileUpload Filter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> 

in your web.xml file and add commons-io and commons-fileupload in your library path?

0
source share

You really have to add commons-io and commons-fileupload libraries. You download them from the following links as .jar files. Then you need to add jar files to your project.

http://commons.apache.org/io/

http://commons.apache.org/fileupload/

After adding these jar files to your project, you can get work with the file system.

0
source share

All Articles