Uploading files in Spring with Tomcat related to the maximum size allowed

后端 未结 1 1866
情话喂你
情话喂你 2021-01-19 17:54

I am considerably new with Spring, and I want to have a multipart form and handle the MaxUploadSizeExceededException exception in order to show an error message in the jsp.

相关标签:
1条回答
  • 2021-01-19 18:39

    After investigating, the problem was due to Tomcat.
    In the version 7.0.55 was introduced the property maxSwallowSize set by default to 2MB. This made Tomcat to abort the upload request. By setting this attribute to another value the problem is solved (I changed it to -1, please do not do that in your PRD environment as Tomcat will really try to get a X MB file to upload). I did this by adding in my Tomcat server file ${tomcat_dir}/conf/server.xml in my connector property the attribute maxSwallowSize

    <Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" 
        maxSwallowSize="-1"/>
    

    You need to restart Tomcat so it takes this configuration, if does not work, delete the server and add it again.

    0 讨论(0)
提交回复
热议问题