Struts2上傳檔案過大解決方案
[@[email protected]] ERROR [http-80-3] MultiPartRequest.parse(130) | org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (102147245) exceeds the configured maximum (50097152)
[@[email protected]] ERROR [http-80-3] FileUploadInterceptor.intercept(227) | the request was rejected because its size (102147245) exceeds the configured maximum (50097152)
解析:這個最大值是在struts2的原始檔“struts2-core-2.0.11.1.jar\org\apache\struts\ default.properties”中的struts.multipart.maxSize=2097152語句,如果想改大的話,就重新設定它,有兩種方法:
一種是重寫:struts.properties檔案。
二是在struts.xml中加入常量來改變它如“ Java程式碼
<constant name="struts.multipart.maxSize" value="10000000" />
當然了,也有struts2的攔截器可以限制檔案的型別、大小等,但是當上傳檔案大小2M後,這個攔截器就不起作用了,只用小於2M(預設大小)的時候才起作用。那是因為:common-fileupload元件預設最大支援上傳檔案的大小為2M,當我們上傳大於2M的檔案時,就會出現上面所說的異常。是這個異常的發生導致了fileUpload攔截器沒有機會執行,所以看到的是頁面沒有任何變化,也沒有任何提示資訊,只是在控制檯打印出了上面的那些上傳檔案過大的異常。
我解決問題的過程:
剛開始只是在struts.xml檔案最上部加入
<constant name="struts.multipart.maxSize" value="1000000000" />
但還是報同樣的錯誤。
接著檢視struts.properties檔案裡的配置為:
### Load custom default resource bundles
struts.custom.i18n.resources=MessageResource
struts.multipart.maxSize=50097152
### character encoding
struts.i18n.encoding=GBK
修改為
### Load custom default resource bundles
struts.custom.i18n.resources=MessageResource
struts.multipart.maxSize=1000000000
### character encoding
struts.i18n.encoding=GBK
問題就解決了。
原文連結:http://www.diybl.com/course/4_webprogram/php/phpxl/2008917/143270.html