我正在使用 apache FileUpload 来处理文件上传。我将它与码头一起使用。servlet 看到多部分请求,但在执行时抛出 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 吗?
我的目标是只上传一个文件并将其写入磁盘。
谢谢