首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

fileupload上传有关问题

2012-01-12 
fileupload上传问题直接帖代码了DiskFileItemFactoryfactorynewDiskFileItemFactory()factory.setSizeTh

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>

热点排行