将单个文件复制到目标后,Struts 多个文件上传出现 FileNotFoundException 问题

Issue with Struts Multiple File Upload getting FileNotFoundException after copying single file to destination

我正在尝试使用 Struts 上传多个文件。在服务器端只复制一个文件。对于其他文件,我得到 java.io.FileNotFoundException

我可以在 ArrayList 中的任何索引处复制文件。但问题是,如果我复制下一个文件,它会抛出异常。

我将单个文件复制到目标后,似乎 .tmp 文件被删除了。

请帮助我解决这个问题 2 天。

动作:

public String upload() throws Exception{
        System.out.println("In Upload action");
        String[] fileNames={"array.txt","pdsn.csv","crm.txt","tipps.txt"};
        //String destPath=request.getServletContext().getRealPath("")+"\ArrayCrmData";
        String destPath=saveDirectory;
        int index=0;
        for (String fileName: fileUploadFileName) {
            System.out.println("Filename : " + fileName);

        }

        for (String fileContentType: fileUploadContentType) {
            System.out.println("File type : " + fileContentType);
        }
        try {

                System.out.println();
                File destFile  = new File(destPath,fileNames[0]);
                FileUtils.copyFile(fileUpload.get(0), destFile);
                System.out.println("Copied:"+destFile.getAbsolutePath()+" From:"+ fileUploadFileName.get(0));
                destFile  = new File(destPath,fileNames[2]);
                FileUtils.copyFile(fileUpload.get(2), destFile);
                System.out.println("Copied:"+destFile.getAbsolutePath()+" From:"+ fileUploadFileName.get(2));
                destFile  = new File(destPath,fileNames[3]);
                FileUtils.copyFile(fileUpload.get(3), destFile);
                System.out.println("Copied:"+destFile.getAbsolutePath()+" From:"+ fileUploadFileName.get(3));
                destFile  = new File(destPath,fileNames[1]);
                FileUtils.copyFile(fileUpload.get(1), destFile);
                System.out.println("Copied:"+destFile.getAbsolutePath()+" From:"+ fileUploadFileName.get(1));
            return SUCCESS;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }return "fail";

    }

JSP

<s:form action="MultiUpload" namespace="/" method="POST" enctype="multipart/form-data">     
    <s:file label="File 1" name="fileUpload"  />
    <s:file label="File 2" name="fileUpload"  />
    <s:file label="FIle 2" name="fileUpload"  />
    <s:file label="FIle 2" name="fileUpload"  />
    <s:submit value="submit" name="submit" />     
</s:form>

Struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
   "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.multipart.maxSize" value="950971520000" />
    <constant name="struts.devMode" value="true" />
    <package name="com" namespace="/" extends="struts-default">
<action name="MultiUpload" class="arrayActions.MultiUpload"
            method="upload">
            <param name="saveDirectory">D:/temp</param>
            <interceptor-ref name="defaultStack">

                <param name="fileUpload.maximumSize">950971510000</param>
            </interceptor-ref>
            <interceptor-ref name="execAndWait" />
            <result name="wait">longRunningAction-wait.jsp</result>
            <result name="success">temp.jsp</result>
            <result name="fail">/uploadFail.jsp</result>
        </action>
    </package>
</struts>

堆栈跟踪:

Unexpected Exception caught setting 'submit' on 'class arrayActions.MultiUpload: Error setting expression 'submit' with value ['submit', ]
In Upload action
Filename : 31Days.txt
Filename : 15Days.txt
Filename : 5days.txt
Filename : april_logins.txt
File type : text/plain
File type : text/plain
File type : text/plain
File type : text/plain
May 25, 2015 12:03:45 PM org.apache.struts2.util.TokenHelper warn
WARNING: Could not find token mapped to token name token
Copied:D:\temp\tipps.txt From:april_logins.txt
java.io.FileNotFoundException: Source 'D:\IDM_Prji\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\FpoAutomation\upload_30ff7d78_f31d_4f15_9222_7f8a47eb26f0_00000002.tmp' does not exist
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1004)
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:968)
    at arrayActions.MultiUpload.upload(MultiUpload.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
    at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
    at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
    at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.Ognl.getValue(Ognl.java:494)
    at ognl.Ognl.getValue(Ognl.java:458)
    at com.opensymphony.xwork2.ognl.OgnlUtil.execute(OgnlUtil.java:309)
    at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
    at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
    at org.apache.struts2.interceptor.BackgroundProcess.run(BackgroundProcess.java:57)
    at java.lang.Thread.run(Thread.java:744)
May 25, 2015 12:03:50 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'submit' on 'class arrayActions.MultiUpload: Error setting expression 'submit' with value ['submit', ]

删除了 "execAndWait" 拦截器。它就像一个魅力。