Struts 2
Struts 2上传文件报错
[13 16:09:13,321 catalina-exec-5] CommonsLogger.warn(56) | Could not find create multipart save directory ‘/attachment‘.
[13 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 (没有那个文件或目录)
...
Caused by: java.io.FileNotFoundException: attachment/upload__58686996_15b664f6902__8000_00000005.tmp (没有那个文件或目录)
at java.io.FileOutputStream.open(Native Method)
...
Root cause:
struts-main.xml指定上传文件的保存位置:
<constant name="struts.multipart.saveDir" value="attachment" />
那么attachment文件夹会创建在user.dir位置下,user.dir为tomcat startup.sh执行时启动的工作目录,一般为tomcat/bin目录;
但如果/xxx/tomcat/bin/startup.sh启动时的当前目录为根目录/,而tomcat启动用户并没有在/目录创建目录的权限,上传文件就会失败,并报错如上。
Solution:
1. 切换tomcat启动时的工作目录
2. 在tomcat启动的任何目录确保可以创建attachment目录
Reference:
关于struts.multipart.saveDir不设置或设置的说明:http://mossad.iteye.com/blog/1522905