为了账号安全,请及时绑定邮箱和手机立即绑定

文件上传问题

文件上传问题

文件上传报错The current request is not a multipart request;JSP页面表单:<form id="upMediaForm" action="${pageContext.request.contextPath}/system/upload/saveUpload" method="post"  enctype="multipart/form-data">         <input type="file" name="file"/>         <a href="#" onclick="save();" class="btn btn-primary radius" >确定</a>&emsp;    </form>逻辑代码:@ResponseBody @RequestMapping("saveUpload") public ModelAndView  saveUpload(HttpServletRequest request, HttpServletResponse response,@RequestParam("file") MultipartFile file)            throws ServletException, IOException {   String name = ""; if (request instanceof MultipartHttpServletRequest) {        // process // 判断文件是否为空          if (!file.isEmpty()) {              try {               name = file.getOriginalFilename();                // 文件保存路径                  String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/"+new Date().getTime()                         + name;                  //如果没有此路径,新建文件夹                File folder = new File(filePath);                if(!folder.exists() || folder.isDirectory()){                 folder.mkdirs();                }                                // 转存文件                  file.transferTo(new File(filePath));              } catch (Exception e) {                  e.printStackTrace();              }          }      }        ModelAndView mv = new ModelAndView("/system/install/saveInstall");        request.setAttribute("mediaName", name);         return mv;  }且本地可以上传,服务器报错已加载jar包  commons-fileupload-1.2.2.jarSpringMVC配置:<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">         <property name="defaultEncoding" value="utf-8" /> </bean>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1184 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信