struts2默认文件上传大小为2M,如需修改默认大小,解决方法如下:
<struts>
<constant name="struts.multipart.maxSize" value="20971520" /> <!-- 设置允许最大值 20MB(1024*1024*20) --> <package name="build" extends="struts-default"> <action name="fileUpload" class="com.home.UploadAction" method="upload">
<result name="success">/success.jsp</result>
<result name="input">/error.jsp</result>
<!-- <param name="allowedTypes"></param> 允许文件类型 -->
<interceptor-ref name="fileUpload">
<param name="maximumSize">5242880</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" /> <!-- 默认拦截器 -->
</action> </package>
</struts>
struts.multipart.maxSize和fileUpload拦截器的maximumSize属性分工不同
1、struts.multipart.maxSize控制整个项目所上传文件的最大size。超过这个值,后台报错
the request was rejected because its size (51224434) exceeds the configured maximum (20971520)
2、fileUpload拦截器的maximumSize属性必须小于struts.multipart.maxSize的值。
struts.multipart.maxSize默认2M,当maximumSize大于2M时,必须设置struts.multipart.maxSize的值大于maximumSize。
3、当上传的文件在maxSize和maximumSize之间时,系统提示
The file is to large to be uploaded: file "apache-tomcat-7.0.47.zip""upload_94d9d06c_a45f_b91e4c915c02_00000002.tmp" 8782342
4、当上传文件小于maximumSize时,上传成功。
总结:所上传文件大小应 < maximumSize < maxSize