struts文件上传——文件过大时错误提示的配置问题说明

开始只在struts.xml文件中加入以下配置

<constant name="struts.multipart.maxSize" value="10000" />

在index.jsp文件中加入的 <s:fielderror/>没有显示

只会在控制台打印错误信息:

警告: Request exceeded size limit!
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (251842) exceeds the configured maximum (10000)

解决方法:

<constant name="struts.multipart.maxSize" value="100000000" />

在拦截器中添加以下配置

    <interceptor-ref name="fileUpload">
                <param name="allowedTypes">image/png,image/jpeg</param>
                <param name="maximumSize">10000</param> <!--此处的值应小于常量中设置的最大值-->
            </interceptor-ref>
            <!-- 默认的拦截器栈 -->
            <interceptor-ref name="defaultStack"/>

结果如下:

<param name="maximumSize">10000</param>中的值设置大一些则该大小文件能正常上传。

说明:根据struts源码/org/apache/struts2/struts-messages.properties

该文件中的此段可得上述结论

struts.messages.bypass.request=Bypassing {0}/{1}
struts.messages.current.file=File {0} {1} {2} {3}
struts.messages.invalid.file=Could not find a Filename for {0}. Verify that a valid file was submitted.
struts.messages.invalid.content.type=Could not find a Content-Type for {0}. Verify that a valid file was submitted.
struts.messages.removing.file=Removing file {0} {1}
struts.messages.error.uploading=Error uploading: {0}
struts.messages.error.file.too.large=File {0} is too large to be uploaded. Maximum allowed size is {4} bytes!
struts.messages.error.content.type.not.allowed=Content-Type not allowed: {0} "{1}" "{2}" {3}
struts.messages.error.file.extension.not.allowed=File extension not allowed: {0} "{1}" "{2}" {3}

转载于:https://www.cnblogs.com/ly-radiata/p/4485260.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值