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}

  • 相关阅读:
    jQuery基础 如何处理网页内容
    jQuery基础 如何判断页面元素存在与否
    什么是 JSON
    动软Codematic生成SQL代码与CodeSmith生成NHibernate代码区别
    jQuery基础 树形结构的选择器
    C# 将汉字转换成拼音
    改善你的jQuery的25个步骤 从头看完会有无数收获,千倍级效率提升
    jQuery基础 添加/移除CSS类
    让数据库支持VS一样的智能提示
    循环输出多维数组
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4485260.html
Copyright © 2011-2022 走看看