(8)common-upload文件上传出现org.apache.commons.fileupload.FileUploadBase$IOFileUploadException

在使用common-upload进行文件上传时,出现了以下错误:

org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. D:\tomcat6.0\webapps\CommonUpl          oadTest2\upload\upload__3f4e9ce4_145b7178a26__8000_00000008.tmp (系统找不到指定的路径。)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at com.xuan.servlet.FileUploadServlet.doPost(FileUploadServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.FileNotFoundException: D:\tomcat6.0\webapps\CommonUploadTest2\upload\upload__3f4e9ce4_145b7178a26__8000_00000008.tmp (系统找不到指定的路径。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
at org.apache.commons.io.output.DeferredFileOutputStream.thresholdReached(DeferredFileOutputStream.java:123)
at org.apache.commons.io.output.ThresholdingOutputStream.checkThreshold(ThresholdingOutputStream.java:220)
at org.apache.commons.io.output.ThresholdingOutputStream.write(ThresholdingOutputStream.java:127)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:101)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
... 16 more

原因在于你在servlet或者处理上传逻辑的时候没有设置好文件存放的路径,你可以在

     String basePath = this.getServletContext().getRealPath("/upload/");
       这句代码的前面加上一句:

    System.out.println(getServletContext().getRealPath("/upload/"));
观察控制台输出的是是什么信息,这时候就会得知在你上传的路径中必须新建某个文件夹才行,比如我的输出如下所示信息:

        D:\tomcat6.0\webapps\CommonUploadTest2\upload
      因此我到相应的目中去寻找,发现没有upload文件夹,于是新建一个文件夹即可,运行成功,upload文件夹中有我上传的文件。




你可能感兴趣的:((8)common-upload文件上传出现org.apache.commons.fileupload.FileUploadBase$IOFileUploadException)