日期:2014-05-16  浏览次数:20459 次

JSP使用File上传文件
1、项目当中在页面使用File上传图片的时候图片超过org.apache.commons.fileupload中的默认大小1M的时候报错:
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 1048576 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (1915754443) exceeds the configured maximum (1048576)
 Caused by: 
 org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (1915754443) exceeds the configured maximum (1048576)
     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.resolveMultipart(CommonsMultipartResolver.java:128)
     at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:982)
     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:835)
     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     at com.twm.adp.management.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:59)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
     at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
     at java.lang.Thread.run(Thread.java:595)
 



这个问题可以在Spring的配置文件里面配置大小:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">      
       <property name="maxUploadSize">               <value>1048576</value>          </property>        <property name="defaultEncoding">              <value>UTF-8</value>          </property>     </bean>