error: package org.apache.commons.fileupload does not exist问题解决方法

编写好Java类,该类依赖2个jar包:commons-fileupload-1.3.1.jar和commons-io-2.4.jar

使用javac编译该类文件,碰到下面的错误:

C:\tools\Tomcat 8.0\webapps\servlet>javac UploadServlet.java
UploadServlet.java:11: error: package org.apache.commons.fileupload does not exist
import org.apache.commons.fileupload.FileItem;

UploadServlet.java:12: error: package org.apache.commons.fileupload does not exist
import org.apache.commons.fileupload.FileUploadException;

UploadServlet.java:13: error: package org.apache.commons.fileupload.disk does not exist
import org.apache.commons.fileupload.disk.DiskFileItemFactory;

UploadServlet.java:14: error: package org.apache.commons.fileupload.servlet does not exist
import org.apache.commons.fileupload.servlet.ServletFileUpload;

UploadServlet.java:15: error: package org.apache.commons.io.output does not exist
import org.apache.commons.io.output.*;

UploadServlet.java:34: error: cannot find symbol isMultipart = ServletFileUpload.isMultipartContent(request);

  symbol:   variable ServletFileUpload
  location: class UploadServlet
UploadServlet.java:48: error: cannot find symbol
      DiskFileItemFactory factory = new DiskFileItemFactory();

  symbol:   class DiskFileItemFactory
  location: class UploadServlet
UploadServlet.java:48: error: cannot find symbol
      DiskFileItemFactory factory = new DiskFileItemFactory();
                    
  symbol:   class DiskFileItemFactory
  location: class UploadServlet
UploadServlet.java:55: error: cannot find symbol
      ServletFileUpload upload = new ServletFileUpload(factory);

  symbol:   class ServletFileUpload
  location: class UploadServlet
UploadServlet.java:55: error: cannot find symbol
      ServletFileUpload upload = new ServletFileUpload(factory);
             
  symbol:   class ServletFileUpload
  location: class UploadServlet
UploadServlet.java:73: error: cannot find symbol
         FileItem fi = (FileItem)i.next();

  symbol:   class FileItem
  location: class UploadServlet
UploadServlet.java:73: error: cannot find symbol
         FileItem fi = (FileItem)i.next();
     
  symbol:   class FileItem
  location: class UploadServlet
12 errors


解决方法:将这两个引用的jar文件添加到classpath环境变量即可。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值