資源描述:
《uploadfiy2.0+servlet實(shí)現(xiàn)多文件上傳顯示進(jìn)度條》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、2.1版本簡(jiǎn)單的web項(xiàng)目+servlet實(shí)現(xiàn)的uploadify上傳需要的jar包,commons-fileupload-1.2.1.jar???commons-io-1.3.2.jar???commons-logging-1.1.jar1:簡(jiǎn)單的web結(jié)構(gòu)這里只列舉需要自己修改或?qū)崿F(xiàn)的代碼:upload.javapackage?servlet;import?java.io.File;import?java.io.IOException;import?java.util.Iterator;import?java.ut
2、il.List;import?java.util.UUID;import?javax.servlet.ServletException;import?javax.servlet.http.HttpServlet;import?javax.servlet.http.HttpServletRequest;import?javax.servlet.http.HttpServletResponse;import?org.apache.commons.fileupload.FileItem;import?org.apache.c
3、ommons.fileupload.FileUploadException;import?org.apache.commons.fileupload.disk.DiskFileItemFactory;import?org.apache.commons.fileupload.servlet.ServletFileUpload;@SuppressWarnings("serial")public?class?Upload?extends?HttpServlet?{????@SuppressWarnings("unchecke
4、d")????public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)????????????throws?ServletException,?IOException?{????????String?savePath?=?this.getServletConfig().getServletContext()????????????????.getRealPath("");????????savePath?=?savePath
5、?+?"/uploads/";????????File?f1?=?new?File(savePath);????????System.out.println(savePath);????????if?(!f1.exists())?{????????????f1.mkdirs();????????}????????DiskFileItemFactory?fac?=?new?DiskFileItemFactory();????????ServletFileUpload?upload?=?new?ServletFileUpl
6、oad(fac);????????upload.setHeaderEncoding("utf-8");????????List?fileList?=?null;????????try?{????????????fileList?=?upload.parseRequest(request);????????}?catch?(FileUploadException?ex)?{????????????return;????????}????????Iterator?it?=?fileList.iterat
7、or();????????String?name?=?"";????????String?extName?=?"";????????while?(it.hasNext())?{????????????FileItem?item?=?it.next();????????????if?(!item.isFormField())?{????????????????name?=?item.getName();????????????????long?size?=?item.getSize();????????????????S
8、tring?type?=?item.getContentType();????????????????System.out.println(size?+?"?"?+?type);????????????????if?(name?==?null?
9、
10、?name.trim().equals(""))?{????????????????