下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
spring mvc CommonsMultipartResolver 文件上传监听。
/** * 重写 parseRequest方法 监听 */ @Override protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException { System.out.println("MultipartParsingResult:--------------------------"+request); String encoding = determineEncoding(request); FileUpload fileUpload = prepareFileUpload(encoding); fileUpload.setFileSizeMax(-1); final HttpSession session = request.getSession(); fileUpload.setProgressListener(new ProgressListener() { @Override public void update(long pBytesRead,long pContentLength,int pItems) { try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } session.setAttribute("pBytesRead",pBytesRead); } }); try { List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request); return parseFileItems(fileItems,encoding); } catch (FileUploadBase.SizeLimitExceededException ex) { throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(),ex); } catch (FileUploadException ex) { throw new MultipartException( "Could not parse multipart servlet request",ex); } }
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
原文链接:https://www.f2er.com/springmvc/460945.html