天天看點

tomcat 8下file upload設定上傳限制後異常無法傳回的解決方法

       無論是用jquery的fileupload還是傳統的form post, 一旦伺服器端設定了附件size限制:

ServletFileUpload upload = new ServletFileUpload(factory);
		upload.setFileSizeMax(AppSetting.c_upload_max_size*1024*1024);
		upload.setSizeMax(AppSetting.c_upload_max_size*1024*1024);
           

tomcat就會中止這個response:

tomcat 8下file upload設定上傳限制後異常無法傳回的解決方法

Chrome也一樣:

tomcat 8下file upload設定上傳限制後異常無法傳回的解決方法

但奇怪的是,如果給chrome設定fiddler代理,居然又OK:

tomcat 8下file upload設定上傳限制後異常無法傳回的解決方法

具體解決方法, 修改tomcat的server.xml配置,在 <Connector port="80" protocol="HTTP/1.1" ...加上屬性 maxSwallowSize="-1" 即可解決.

如:

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
compression="on"
compressionMinSize="2048"
maxSwallowSize="-1"
noCompressionUserAgents="gozilla,traviata"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"

redirectPort="8443" />