主题: 我的是spring mvc 2.5文件上传的,items长度为0怎么解决?qq243517277 |
作者: waitingFor, 发布日期: 2013-08-29 22:46:52, 浏览数: 3089 |
public void JDTFileupload(HttpServletRequest request, HttpServletResponse response){
DiskFileItemFactory factory = new DiskFileItemFactory(); boolean isMultipart= ServletFileUpload.isMultipartContent(request); System.out.println("isMultipart-----------------------"+isMultipart); System.out.println("request--------------------------"+request); // 设置内存缓冲区,超过后写入临时文件 factory.setSizeThreshold(10240000); // 设置临时文件存储位置 String base = "d:/upload"; File file = new File(base); if(!file.exists()) file.mkdirs(); factory.setRepository(file); ServletFileUpload upload = new ServletFileUpload(factory); // 设置单个文件的最大上传值 //upload.setFileSizeMax(100024000000l); // 设置整个request的最大值 upload.setSizeMax(100024000000l); upload.setHeaderEncoding("UTF-8"); try { List<?> items = upload.parseRequest(request); FileItem item = null; String fileName = null; for (int i = 0 ;i < items.size(); i++){ item = (FileItem) items.get(i); fileName = base + File.separator + item.getName(); // 保存文件 if (!item.isFormField() && item.getName().length() > 0) { item.write(new File(fileName)); System.out.println("fileName----------------------------"+fileName); } } } catch (FileUploadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } |