Struts 2约定插件 - 上传超过2 MB的文件 [英] Struts 2 convention plugin - upload a file of more than 2 MB

查看:210
本文介绍了Struts 2约定插件 - 上传超过2 MB的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试上传超过2 MB大小的文件,则会显示错误。

我在apache网站上发现有两个单独的文件大小限制,首先是struts.multipart.maxSize来自Struts 2的default.properties文件。设置是出于安全原因,禁止恶意用户上传超大文件来提交服务器的磁盘空间,这个设置默认为2兆字节,应该调整到最大文件大小(最多2个),你需要的框架接收

所以我发现这个问题可以通过添加具有所需最大限制< constant name =struts的标签来解决。我们正在使用struts2-convention-plugin,所以我们使用struts2-convention-plugin来实现这个功能。我们没有struts.xml。所以我不知道在哪里定义这个最大文件大小...

请让我知道你是否有任何一个人遇到过这个问题。



感谢您的帮助。

解决方案


  1. 您可以在Struts.xml中定义最大大小( multipart.maxSize ,如您所述),以限制每个多部分请求的整体传输;您还可以为全局变量FileUpload Interceptor (默认为2MB)定义文件大小(通过在 struts.xml 中的< action> 标签中配置该Interceptor的参数)使用 规则插件 :: > < param name =maximumSize> 10485760< / param>
    < / interceptor-ref>






    这意味着如果你配置了一个20 MB的整体多部分大小,每个文件的最大大小为4MB,您可以在一个请求中执行5个4MB文件的多次上传;


    更多信息: https://stackoverflow.com/a/15968166/1654265






    d,你的问题是没有问题的; 使用常规插件 并不意味着您没有 struts.xml >;这意味着您可以在操作中使用注释

    $ b


    • 您可以当某些struts配置与动作无关时,可避免使用 struts.xml ;

    • multipart.maxSize,全局映射(结果,异常,自定义拦截器堆栈等)是必须的,你绝对可以使用struts.xml创建它,如果直到那一刻才出现)。

      $ b $ < Convention Plugin Documentation 中提到,它与 struts.xml (相反,如果您尝试在该页面上搜索 struts.xml ,则会发现多处出现)


      If i try to upload a file of more than 2 MB size its error-ed.

      I found in apache web site saying "There are two separate file size limits. First is struts.multipart.maxSize which comes from the Struts 2 default.properties file. This setting exists for security reasons to prohibit a malicious user from uploading extremely large files to file up your servers disk space. This setting defaults to approximately 2 megabytes and should be adjusted to the maximum size file (2 gigs max) that your will need the framework to receive"

      So I found that this issue can be solved by adding the tag with the desired max limit <constant name="struts.multipart.maxSize" value="1000000" /> in struts.xml file.

      We are using struts2-convention-plugin, so we don't have struts.xml. So I was not sure where to define this max file size...

      Please let me know if any one of you have come across on this..

      Appreciate for your help.

      解决方案

      1. You can define a max size in Struts.xml (multipart.maxSize , as you said) to limit the overall transfer for each multipart request;

      2. You can also define a file Size for the FileUpload Interceptor (default 2MB), both globally to a package, and for a single Action (by configuring that parameter for that Interceptor in the <action> tag in struts.xml, or by Annotating it inside the Action when using the Convention plugin:

        <interceptor-ref name="fileUpload">
            <param name="maximumSize">10485760</param>
        </interceptor-ref>
        

      This means that if, for example, you configure an overall multipart size of 20 MB, a maximumSize-per-file of 4MB, you will be able to perform a multiple upload of 5 files of 4MB in a single request;

      More info here: https://stackoverflow.com/a/15968166/1654265


      That said, your problem is a non-problem;

      using Convention plugin does not mean you don't have a struts.xml; it means that

      • you can use Annotations in Actions
      • you may avoid using a struts.xml;
      • when some struts configuration not action-related, like multipart.maxSize, global mappings (results, exceptions, custom interceptor stack, etc) is needed, you absolutely can use struts.xml (create it, if it wasn't present until that moment).

      Nowhere in the Convention Plugin Documentation, is mentioned that it is mutually exclusive to the struts.xml (instead, if you try to search on that page "struts.xml", you will find several occurrences)

      这篇关于Struts 2约定插件 - 上传超过2 MB的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆