zoukankan      html  css  js  c++  java
  • 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}

  • 相关阅读:
    vue.js 初步学习
    IntelliJ IDEA 快捷键
    SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因
    JavaScript基础概念与语法
    python 常见矩阵运算
    利用matplotlib的plot函数实现图像绘制
    基于密度峰值的聚类(DPCA)
    极角排序
    HDU-5514 Frogs (容斥)
    HDU
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4485260.html
Copyright © 2011-2022 走看看