Strange FileNotFoundExceptionwhen downloading a file using Struts2. This is part of the JSP:
<a:form action="/FileUploadServletAction.action" method="post" enctype="multipart/form-data">
<a:file name="fileUpload" label="File"/>
<a:submit/>
This is the execute () method to copy the downloaded file from a temporary location to the actual location:
public String execute() throws Exception{
try {
String filePath = "c:/foo";
System.out.println("Server path:" + filePath);
File fileToCreate = new File(filePath, this.fileUploadContentType);
FileUtils.copyFile(this.fileUpload, fileToCreate);
} catch (Exception e) {
e.printStackTrace();
addActionError(e.getMessage());
return INPUT;
}
return SUCCESS;
}
This is my part of struts.xml, which is configured above the Action class:
<action name="FileUploadServletAction"
class="com.test.FileUploadServletAction">
<result name="input">/jsp/upload.jsp</result>
<result name="success">/jsp/upload.jsp</result>
<result name="error">/jsp/error.jsp</result>
</action>
But when I run, I get this exception:
java.io.FileNotFoundException: Source 'E:\Foo\Projects\Foo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FooProject\upload_1ec6cc50_75d7_482f_83be_fe4185999973_00000000.tmp' does not exist
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1074)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
INFO: Removing file fileUpload E:\Foo\Projects\Foo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FooProject\upload_1ec6cc50_75d7_482f_83be_fe4185999973_00000000.tmp
Can anyone tell me why Struts cannot find the temporary file that was created? Please let me know if you need more information.
source
share