【问题标题】:Restricting the file type in struts2 using "allowedTypes" parameter使用“allowedTypes”参数限制struts2中的文件类型
【发布时间】:2015-11-09 15:11:30
【问题描述】:

我有一个表单,用户只能上传 pdf 文件。我使用以下 struts 操作来限制大小和文件类型,但只有大小限制有效。关于我所缺少的任何想法?谢谢!

    <action name="commentAction" class = "gov.mo.dnr.rat.controller.comment.CommentAction">
        <interceptor-ref name="validUserStack">
            <param name="fileUpload.maximumSize">5242880</param>
            <param name="allowedTypes">application/pdf</param>
        </interceptor-ref>
        <result name="success" type="tiles">comment</result>
        <result name="input" type="tiles">comment</result>
    </action>           

【问题讨论】:

  • 作为maximumSize,allowedTypes是fileUpload拦截器的一个参数,如果在栈内使用则需要加前缀十 def:&lt;param name="fileUpload.allowedTypes"&gt;application/pdf&lt;/param&gt;,如described here。最后只是一个错字,所以不需要回答

标签: java struts2 struts2-interceptors


【解决方案1】:

我发现了问题。在这种情况下,allowedTypes 应该是 fileUpload.allowedTypes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-20
    • 2015-12-26
    • 2021-06-27
    • 1970-01-01
    • 2010-12-30
    • 2023-02-22
    • 2022-06-15
    • 1970-01-01
    相关资源
    最近更新 更多