日期:2014-05-18  浏览次数:20746 次

fileupload上传问题
直接帖代码了

DiskFileItemFactory   factory   =   new   DiskFileItemFactory();
factory.setSizeThreshold(1024   *   10);
factory.setRepository(new   File( "d://test "));

ServletFileUpload   upload   =   new   ServletFileUpload(factory);
upload.setSizeMax(1024   *   1024   *   4);

List   items   =   upload.parseRequest(request);
Iterator   iter   =   items.iterator();

//问题就是这里
//   items.size()   为0  
System.out.println(items.size());


while   (iter.hasNext())   {
          FileItem   item   =   (FileItem)   iter.next();
        .........
}

请问是什么原因造成的

------解决方案--------------------
DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(-1);
upload.setRepositoryPath(currentPath);//要保存的路径

List items = upload.parseRequest(request);
Iterator iter = items.iterator();
我这个是行的,DiskFileUpload.

页面写好没有?
<FORM name=uploadForm action=upload.jsp method=post encType= 'multipart/form-data '>
Please select one file to upload:
<INPUT type=file size=100 name=uploadFile> <input type=submit name=uploadButton value= 'Start upload ' onClick= "displayLoadingBar( 'Uploading file, please wait... ') ">
</FORM>