江丶小鱼
2017-04-07 03:59
采纳率: 20%
浏览 4.6k
已采纳

java ssm框架 文件上传,获取不到文件

     控制器中方法:
             @RequestMapping(value = "/upload2")
public void uploadFile2(HttpServletRequest request, HttpServletResponse response) {
    try {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<MultipartFile> fileList = multipartRequest.getFiles("file");

        for (MultipartFile mf : fileList) {
            if(!mf.isEmpty()){
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

    jsp页面:
    <form action="upload2" value="file" enctype="multipart/form-data" method="post" >
<div style="margin-bottom:10px;">
    <input type="file"    value="file" id="image" />
    <input type="submit"   value="提交" />
</div>

  xml配置文件:

<bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="defaultEncoding" value="UTF-8" />

    <property name="maxUploadSize" value="2000000000" />
</bean>

    在控制器中multipartRequest.getFiles("file")获取的list为0,有大神知道问题出在哪吗?
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

11条回答 默认 最新

相关推荐 更多相似问题