Struts 2 convention plugin - upload a file of more than 2 MB

前端 未结 2 1795
太阳男子
太阳男子 2021-01-25 10:47

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.ma

相关标签:
2条回答
  • 2021-01-25 11:25
    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)

    0 讨论(0)
  • 2021-01-25 11:40

    You have to change too the server.xml file under conf folder in your apache directory. Find the connector tag you are using and add what maxPostSize you want, in bytes:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
               maxPostSize="2097152" />
    
    0 讨论(0)
提交回复
热议问题