Struts 2
Struts 2 upload file error
[16:09:13,321 catalina-exec-5] Commonslogger.warn (56) | Could not find create multipart save directory '/attachment '.
[16:09:13,323 catalina-exec-5] Commonslogger.warn (60) | Unable to parse request
Org.apache.commons.fileupload.fileuploadbase$iofileuploadexception:processing of Multipart/form-data Request Failed. Attachment/upload__58686996_15b664f6902__8000_00000005.tmp (without that file or directory)
...
caused by:java.io.filenotfoundexception:attachment/upload__58686996_15b664f6902__8000_00000005.tmp (without that file or directory)
At Java.io.FileOutputStream.open (Native Method)
...
Root Cause:
Struts-main.xml specify where to save the uploaded file:
<constant name= "Struts.multipart.saveDir" value= "attachment"/>
Then the attachment folder will be created in the User.dir location, User.dir for the Tomcat startup.sh to start the working directory, generally tomcat/bin directory;
However, if the current directory at/xxx/tomcat/bin/startup.sh startup is the root directory/, and the Tomcat startup user does not have permission to create a directory in the/directory, uploading the file will fail with an error as above.
Solution:
1. Switch the working directory when Tomcat starts
2. Make sure that the attachment directory can be created in any directory launched by Tomcat
Reference:
Notes on Struts.multipart.saveDir not set or set: http://mossad.iteye.com/blog/1522905
Spring Struts Hibernate Trouble Shooting | A record of some problems