Problem
In Struts framework, hit the following exception in file upload process.
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
Solution
Struts is using the “commons-fileupload.jar” library for the file upload process. You have to include this library into your project dependency library folder.
1. Get “commons-fileupload.jar” from official website – http://commons.apache.org/fileupload/
2. Get “commons-fileupload.jar” from Maven repository
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency>