//设置上传文件保存路径 String filePath = getServletContext().getRealPath("/") + "images"; System.out.println(filePath); File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } SmartUpload su = new SmartUpload(); //初始化对象 su.initialize(getServletConfig(), request, response); //设置上传文件大小 su.setMaxFileSize(1024*1024*10);//为10M //设置所有文件的大小 su.setTotalMaxFileSize(1024*1024*100);//为100M //设置允许上传文件类型 su.setAllowedFilesList("txt,jpg,gif,mp3"); String result = "上传成功"; //设置禁止上传文件类型 try { su.setDeniedFilesList("rar,jsp,sj"); //上传文件 su.upload(); int count = su.save(filePath); System.out.println("上传成功" + count + "个文件!"); } catch (Exception e) { result = "上传失败"; e.printStackTrace(); } request.setAttribute("result", result); request.getRequestDispatcher("02.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }
去相应的你的这个发布目录找一下E:\javaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UploadandDownload
你这个问题解决了没,怎么解决的啊,求告知
可以检查一下jsp页面中,表单中input file 中是否有name属性,没有的话就上传不了