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>
本文介绍了在使用Struts框架进行文件上传时遇到的NoClassDefFoundError异常,并提供了详细的解决方案,包括添加依赖库commons-fileupload.jar的方法。

1149

被折叠的 条评论
为什么被折叠?



