首页 新闻 搜索 专区 学院

springmvc 多文件上传 MultipartFile , 怎么获取前台传过来的参数呢

0
悬赏园豆:5 [待解决问题]
1 public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name){
2 List<MultipartFile> files = (List<MultipartFile>) request.getFile("myfiles");
3 }
4 //修改成如下方法,还是报同样下面的错误:
5 public String upload2(MultipartHttpServletRequest request, @RequestParam("name") String name, // 页面上的控件值
6             @RequestParam MultipartFile[] myfiles) {
7 List<MultipartFile> files = Arrays.asList(myfiles);
8 }
9 // 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 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)
问题补充:

在线等,期待解答...

love_zongming的主页 love_zongming | 初学一级 | 园豆:194
提问于:2013-07-11 11:27
< >
分享
所有回答(5)
-1

试试 request.getParameter("name")

dudu | 园豆:38801 (高人七级) | 2013-07-11 11:41
-1

修改了spring版本,2.5.6 修改为3.2.2,可以使用

request.getFiles("myfiles");
love_zongming | 园豆:194 (初学一级) | 2013-07-11 16:48
0

 public @ResponseBody Result insertInfo(@RequestParam MultipartFile file,

不要[]看看

D"川 | 园豆:202 (菜鸟二级) | 2013-07-12 11:50

支持(0) 反对(1) D"川 | 园豆:202 (菜鸟二级) | 2013-07-12 11:53
0

大侠 ,结果怎么样了啊。

风刃风翼 | 园豆:202 (菜鸟二级) | 2015-11-04 20:22
0

页面用HTML5 试试这个 <input type="file" name="myfiles" multiple="multiple" /> 

CNCC | 园豆:218 (菜鸟二级) | 2016-05-12 17:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册