Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
966 views
in Technique[技术] by (71.8m points)

jsf 2 - JSF Configuration of the file upload filter

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...