问题描述
<div class="iteye-blog-content-contain" style="font-size: 14px"></div>public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name){List<MultipartFile> files = (List<MultipartFile>) request.getFile("myfiles");}//修改成如下方法,还是报同样下面的错误:public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name, // 页面上的控件值@RequestParam MultipartFile[] myfiles) {List<MultipartFile> files = Arrays.asList(myfiles);}// jsp页面,传一个myfiles,单个文件是可以通过的,<form method="POST" action="multipartFileUpload.action"enctype="multipart/form-data"><input type="text" name="name" /><br> <input type="file"name="myfiles" /><br><input type="file"name="myfiles" /><br><input type="submit" /><br></form>报错:org.springframework.web.multipart.MultipartException: Multiple files for field name [myfiles] found - not supported by MultipartResolverat org.springframework.web.multipart.commons.CommonsFileUploadSupport.parseFileItems(CommonsFileUploadSupport.java:254)at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:166)at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:149)at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1015)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:851)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)at java.lang.Thread.run(Thread.java:619) 问题补充:在线等,期待解答...
解决方案
你的spring和commons-fileupload版本是多少。我使用spring3.2.2 commons-fileupload:1.2.2没有问题
解决方案二:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
解决方案三:
<input type="file"name="myfiles" /><br> <input type="file"name="myfiles" /><br> 上面的name改成不一样试试,然后代码里边MultipartFile file1 = (MultipartFile) request.getFile("myfiles"); MultipartFile file2 = (MultipartFile) request.getFile("myfiles2");这样子试试。
解决方案四:
http://www.verydemo.com/demo_c143_i23854.html