upload
File saveDir=new File("D:/Test/UPLOAD"); if(!saveDir.isDirectory()){ saveDir.mkdirs(); } File repository = (File) getServletConfig().getServletContext().getAttribute("javax.servlet.context.tempdir"); DiskFileItemFactory factory = new DiskFileItemFactory(10*1024*1024, repository); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(10*1024*1024); // Parse the reques* try { List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter=items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if(!item.isFormField()){ String filename=item.getName(); System.out.println(filename); item.write(new File(saveDir,filename)); upload_msg="上传成功!"; } } } catch (FileUploadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }