我是第一次接触文件上传,所以又很多问题想问!我想先通过apache提供的组件完成文件上传,使用过了就方便以后了解,所以想问那位大侠有源码,最好详细些,本人刚工作不久,很多都不懂!十分感谢!

解决方案 »

  1.   

    网上有视频的,也可以找资料的
    自己稍微弄下,用commons-fileupload上传应该不太难吧
    同时也是对自己自学能力的提高
      

  2.   

    看看 commons-fileupload 的文档示例就能看会了,呵呵。
      

  3.   

    建议你百度去搜一下:JAVA文件上传代码示例里面会有很多代码下载,你想用什么样的方法实现就用什么方法实现.......有很多的
      

  4.   

    这东西网上多的是,而且像火龙果说的那样,下载官方apache的commons-fileupload的时候文档中就会有实例,比如The following is a brief example of typical usage in a servlet, storing the uploaded files on disk.     public void doPost(HttpServletRequest req, HttpServletResponse res) {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            // maximum size that will be stored in memory
            factory.setSizeThreshold(4096);
            // the location for saving data that is larger than getSizeThreshold()
            factory.setRepository(new File("/tmp"));        ServletFileUpload upload = new ServletFileUpload(factory);
            // maximum size before a FileUploadException will be thrown
            upload.setSizeMax(1000000);        List fileItems = upload.parseRequest(req);
            // assume we know there are two files. The first file is a small
            // text file, the second is unknown and is written to a file on
            // the server
            Iterator i = fileItems.iterator();
            String comment = ((FileItem)i.next()).getString();
            FileItem fi = (FileItem)i.next();
            // filename on the client
            String fileName = fi.getName();
            // save comment and filename to database
            ...
            // write the file
            fi.write(new File("/www/uploads/", fileName));
        }
      

  5.   

    建议使用 Richfaces上传控件,支持上传进度条、支持多文件、文件筛选,上传文件超级简单