macoo

记录收获的点点滴滴

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在做struts2的多文件上传时,选择了几个比较大的文件,点击“提交”后,画面没有提示说文件太大,而是清空了各个表单项,查看控制台显示如下错误:

严重: org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (171862030) exceeds the configured maximum (2000000)
2010-2-22 16:58:52 org.apache.struts2.interceptor.FileUploadInterceptor intercept
严重: the request was rejected because its size (171862030) exceeds the configured maximum (2000000)
2010-2-22 16:58:52 org.apache.struts2.interceptor.FileUploadInterceptor intercept
严重: the request was rejected because its size (171862030) exceeds the configured maximum (2000000)

(注:2000000处其实是个大小接近这个数的数字,应该是2M的byte数)

此时的拦截器的配置参数为:

<interceptor-ref name="fileUpload">
        <param name="allowedTypes">image/bmp,image/png,image/gif,image/jpeg</param>
        <param name="maximumSize">50000</param>
       </interceptor-ref>

解决方法:在struts.properties中添加属性:struts.multipart.maxSize=10000000,即指明一次multipart请求的最大size为10M(默认为2M,即在错误信息中看到的那个2XXXXXX)。这样的话,上传50K-10M的图片时,会有自定义的"文件太大"的提示,但是文件超过10M时,又会出现以上问题,只是2XXXXXX会改成10000000。

posted on 2010-02-22 17:16  macoo  阅读(819)  评论(0编辑  收藏  举报