public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getSession().getAttribute("user")!=null){ boolean isMultPart=ServletFileUpload.isMultipartContent(request); String path=request.getSession().getServletContext().getRealPath("project/"); File file=new File(path); ///usr/local/tomcat/webapps/go4mi/project/ path=path.substring(0,path.length()-14); if(!(file.exists())){ file.mkdir(); } if(isMultPart){ FileItemFactory factory=new DiskFileItemFactory(); ServletFileUpload upload=new ServletFileUpload(factory); try { List<FileItem> list = upload.parseRequest(request); Iterator<FileItem> items=list.iterator(); System.out.println(list.size()); while(items.hasNext()){ FileItem item = items.next(); if(!(item.isFormField())){ String fileName = item.getName();//全路径 if(fileName!=null&& !fileName.equals("")){ File projectFile=new File(fileName); File saveFile=new File(path,projectFile.getName());//把文件上传到指定目录 item.write(saveFile);//上传操作 Message_UserInfo user = (Message_UserInfo) request.getSession().getAttribute("user"); UpLoad ul =new UpLoad(); ul.setFileip(request.getRemoteAddr()); ul.setProjectname(fileName); ul.setUname(user.getUname()); ul.setUserid(user.getUserid()); UploadService uls=new UploadServiceImpl(); if(uls.addFile(ul)){ response.sendRedirect(request.getContextPath()+"/jsp/success.html"); }else{ response.sendRedirect(request.getContextPath()+"/jsp/failed.html"); } } } } } catch (Exception e) { e.printStackTrace(); } } }else { System.out.println("zhuanga"); response.sendRedirect(request.getContextPath()+"/jsp/login.jsp"); } }