springMVC+commons-fileupload上传文件大小限制异常
异常信息:
严重: Servlet.service() for servlet [suibian] in context with path [/SpringMvcDemo3] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 10 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9923) exceeds the configured maximum (10)] with root cause
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9923) exceeds the configured maximum (10)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:797)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:323)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:341)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:158)
解决办法:
1 <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 --> 2 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 3 <property name="defaultEncoding" value="UTF-8"/> 4 5 <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 --> 6 <property name="maxUploadSize" value="2000"/> 7 8 <!--resolveLazily属性启用是为了推迟文件解析,以便在UploadController 中捕获文件大小异常--> 9 <property name="resolveLazily" value="true"/> 10 </bean>
作 者:
Jony.K.Chen
出 处:http://www.cnblogs.com/lxcy/
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!