我正在使用apache FileUpload来处理..文件上传。我在码头上用它。 servlet看到multipart请求,但在执行时抛出NoClassDefFoundError异常:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (isMultipart) {
try {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(req); // exception
...
抛出:
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)
引起:
java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
除了commons-fileupload-1.2.2.jar,我们还需要包含一个额外的jar吗?
我的目标是只上传一个文件并将其写入磁盘。
由于
答案 0 :(得分:14)
您需要将CommonsIO添加到类路径中。 Commons File Upload取决于它。
答案 1 :(得分:3)
添加以下依赖项
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>