struts2文件上传最大值配置

使用Struts2的文件上传控件时,在struts.xml中,将处理上传的action中的fileUpload拦截器的maximumSize

参数设置为5000000,上传了一个3M的文件后发现控制台报错,而且提示说文件超过2M。Struts.xml相关配置如下:
<action name="FileUpload" class="cn.timefly.strutsTest.FileUploadAction">
<result name="success">/FileUploadResult.jsp</result>
<result name="input">/FileUpload.jsp</result>
<interceptor-ref name="fileUpload">
<param name="maximumSize">500000</param>
<param name="allowedTypes">application/vnd.ms-powerpoint</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
</action>

后来尝试在struts.xml中加入 <constant name="struts.multipart.maxSize" value="9000000"/>
发现一切正常了,不报错了。功能也正常了。
发现struts.multipart.maxSize和fileUpload拦截器的maximumSize属性分工不同,总结如下:
1.struts.multipart.maxSize掌控整个项目所上传文件的最大的Size。超过了这个size,后台报错,程序处理不了如此大的文件。fielderror里面会有如下的提示:
the request was rejected because its size (16272982) exceeds the configured maximum (9000000)
2.fileUpload拦截器的maximumSize属性必须小于struts.multipart.maxSize的值。
struts.multipart.maxSize默认2M,当maximumSize大于2M时,必须设置struts.multipart.maxSize的值大于maximumSize。
3.当上传的文件大于struts.multipart.maxSize时,系统报错
当上传的文件在struts.multipart.maxSize和maximumSize之间时,系统提示:
File too large: file "MSF的概念.ppt" "upload__5133e516_129ce85285f__7ffa_00000005.tmp" 6007104
当上传的文件小于maximumSize,上传成功。


又:
filesupload拦截器的maximumsize参数只是设定了Action能接受的文件的最大长度,在Action处理之前,文件已经上传到服务器了,如果实现对长度进行限制,需要通过设置struts.multipart.maxsize属性来实现。

又:
Finally solved the entire puzzle! struts.xml and MessageResource.properties were correctly configured. The problem was struts.multipart.maxSize value. This value have to be bigger than the desired upload limit (5242880 in my app), so I set it as 10000000. If struts.multipart.maxSize value is equal or less then fileUpload.maximumSize the library used by Struts 2 to do the upload stops the upload process (and writes the error message) before the file upload interceptor has a chance to do its job.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值