Struts2上传文件错误
Struts2 upload file error
我想将文件上传到我的网络项目,但我得到:
WARN o.a.struts2.dispatcher.Dispatcher - Could not find create multipart save directory '/temp'.
WARN o.a.s.d.m.JakartaMultiPartRequest - Unable to parse request
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException:
Processing of multipart/form-data request failed.
/temp/upload_1e39874d_effe_405b_9a92_3050ca60a661_00000000.tmp
(No such file or directory)
所以我想更改上传目录
<struts>
<constant name="struts.multipart.saveDir" value="/tmp"></constant>
<package name="brand-struts" extends="abstract-struts">
<action name="saveBatchBrandGoodsInfo" class="brandgoodsAction"
method="saveBatchBrandGoodsInfo">
<interceptor-ref name="fileUpload">
<param name="savePath">/upload</param>
<param name="maximumSize">1024000</param>
</interceptor-ref>
<result name="data" type="json">
<param name="root">data</param>
</result>
</action>
</package>
</struts>
但它不起作用,我一直收到同样的错误
据我所知,没有 abstract-struts
包这样的东西。只需扩展 struts-default
并删除 savePath
自定义。
您只包含 fileUpload 拦截器,而不是整个 defaultStack。你需要做的:
<interceptor-ref name="defaultStack">
<param name="fileUpload.maximumSize">1024000</param>
</interceptor-ref>
还要确保您的表单具有 enctype="multipart/form-data"
.
我想将文件上传到我的网络项目,但我得到:
WARN o.a.struts2.dispatcher.Dispatcher - Could not find create multipart save directory '/temp'. WARN o.a.s.d.m.JakartaMultiPartRequest - Unable to parse request org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.
/temp/upload_1e39874d_effe_405b_9a92_3050ca60a661_00000000.tmp
(No such file or directory)
所以我想更改上传目录
<struts>
<constant name="struts.multipart.saveDir" value="/tmp"></constant>
<package name="brand-struts" extends="abstract-struts">
<action name="saveBatchBrandGoodsInfo" class="brandgoodsAction"
method="saveBatchBrandGoodsInfo">
<interceptor-ref name="fileUpload">
<param name="savePath">/upload</param>
<param name="maximumSize">1024000</param>
</interceptor-ref>
<result name="data" type="json">
<param name="root">data</param>
</result>
</action>
</package>
</struts>
但它不起作用,我一直收到同样的错误
据我所知,没有
abstract-struts
包这样的东西。只需扩展struts-default
并删除savePath
自定义。您只包含 fileUpload 拦截器,而不是整个 defaultStack。你需要做的:
<interceptor-ref name="defaultStack"> <param name="fileUpload.maximumSize">1024000</param> </interceptor-ref>
还要确保您的表单具有 enctype="multipart/form-data"
.