龙西庄庄主
2013-07-11 11:24
采纳率: 0%
浏览 723
已采纳

springmvc 多文件上传 MultipartFile

[code="java"]
public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name){
List files = (List) request.getFile("myfiles");
}
//修改成如下方法,还是报同样下面的错误:
public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name, // 页面上的控件值
@RequestParam MultipartFile[] myfiles) {
List files = Arrays.asList(myfiles);
}
// jsp页面,传一个myfiles,单个文件是可以通过的,
[/code]
[code="html"]





[/code]

报错:[code="java"]

org.springframework.web.multipart.MultipartException: Multiple files for field name [myfiles] found - not supported by MultipartResolver
at 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)

[/code]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • jinnianshilongnian 2013-07-11 14:06
    已采纳

    你的spring和commons-fileupload版本是多少。

    我使用spring3.2.2 commons-fileupload:1.2.2没有问题

    点赞 评论
  • zyn010101 2013-07-11 13:29
    点赞 评论
  • softhustwen 2013-07-11 16:33





    上面的name改成不一样试试,然后代码里边
    MultipartFile file1 = (MultipartFile) request.getFile("myfiles");

    MultipartFile file2 = (MultipartFile) request.getFile("myfiles2");

    这样子试试。

    点赞 评论
  • iteye_3681 2014-05-31 17:02
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
    
    点赞 评论

相关推荐 更多相似问题