JSF Configuration of the file upload filter

↘锁芯ラ 提交于 2019-11-27 07:11:57

问题


I am trying to use fileUpload component. As I read from primefaces user guide, I have to configure the fileUpload filter.

<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>

I added these lines (suggested by the guide) to the web.xml file.

Now, when the server (Tomcat 7) is starting, I get an exception and the server fails to start. I'll post part of stack trace.

GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/webApp]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
at....
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

Is the configuration of this filter useful? How can I configure it properly?


回答1:


The PrimeFaces user guide (page 14) lists the required dependencies for p:fileUpload:

  • commons-fileupload
  • commons-io

Seems that you are missing the first dependency.

You can either download and place those files into /WEB-INF/lib or - if your project is a maven project - add the following dependencies to your pom.xml, <dependencies> section:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2.2</version>
</dependency>

Versions may differ, currently I have this in my pom.xml



来源:https://stackoverflow.com/questions/13359033/jsf-configuration-of-the-file-upload-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!