資源簡介
SWFupload實現多文件上傳,效果圖如qq文件上傳那樣

代碼片段和文件信息
package?com.sh.common;
import?java.io.File;
import?java.io.IOException;
import?java.io.PrintWriter;
import?java.text.SimpleDateFormat;
import?java.util.Iterator;
import?java.util.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.commons.fileupload.FileItemFactory;
import?org.apache.commons.fileupload.disk.DiskFileItemFactory;
import?org.apache.commons.fileupload.servlet.ServletFileUpload;
import?com.sun.org.apache.xml.internal.security.exceptions.base64DecodingException;
import?com.sun.org.apache.xml.internal.security.utils.base64;
public?class?FileUploadServlet?extends?HttpServlet?{
private?static?final?int?UPLOAD_SUCCSSS=0;????//?“上傳文件成功!“?
private?static?final?int?UPLOAD_FAILURE=1;????//?“上傳文件失敗!“)?
private?static?final?int?UPLOAD_TYPE_ERROR=2;?//?“上傳文件類型錯誤!“)?
private?static?final?int?UPLOAD_OVERSIZE=3;???//?“上傳文件過大!“)
private?static?final?int?UPLOAD_ZEROSIZE=4;???//?“上傳文件為空!“)
private?static?final?int?UPLOAD_NOTFOUND=5;???//?“上傳文件路徑錯誤!“)
public?void?doGet(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
doPost(requestresponse);
}
public?void?doPost(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
response.setContentType(“text/html;?charset=UTF-8“);
PrintWriter?out=response.getWriter();
?String?rootPath?=?request.getParameter(“rootPath“);??
?String?param?=?request.getParameter(“param“);
?
?if(rootPath?==?null)?rootPath?=?““;??
????rootPath?=?rootPath.trim();??
?if(rootPath.equals(““)){??
?rootPath?=?this.getServletContext().getRealPath(““);??
?}??
?//上傳操作??
??FileItemFactory?factory?=?new?DiskFileItemFactory();??
??ServletFileUpload?upload?=?new?ServletFileUpload(factory);??
??upload.setHeaderEncoding(“UTF-8“);??
??try{??
??????List?items?=?upload.parseRequest(request);??
??????if(null?!=?items){??
??????????Iterator?itr?=?items.iterator();??
??????????while(itr.hasNext()){??
??????????????FileItem?item?=?(FileItem)itr.next();
??????????????if(item.isFormField()){??
?????????????????continue;??
??????????????}else{??
???????????????????//以當前精確到秒的日期為上傳的文件的文件名??
??????????????????SimpleDateFormat?sdf=new?SimpleDateFormat(“yyyyMMddkkmmss“);?
??????????????????String?path=“/files“;
??????????????????File?savedFile?=?new?File(rootPath+pathitem.getName());??
??????????????????item.write(savedFile);?
??????????????????
??????????????????out.print(“{status:“+this.UPLOAD_SUCCSSS+“message:‘“+path+“/“+item.getName()+“‘}“);
??????????????}??
??????????}??
??????}??
??}catch(Exception?e){??
??????e.printStackTrace();??
??}
}
?/**?
?????*?ne
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-12-26?18:58??swfupload\
?????文件?????????529??2012-12-13?15:49??swfupload\.classpath
?????目錄???????????0??2012-12-27?14:07??swfupload\.myeclipse\
?????文件?????????300??2012-12-24?19:20??swfupload\.myme
?????文件????????1752??2012-12-13?17:54??swfupload\.project
?????目錄???????????0??2012-12-13?15:49??swfupload\.settings\
?????文件?????????500??2012-12-13?15:49??swfupload\.settings\.jsdtscope
?????文件?????????364??2012-12-13?15:49??swfupload\.settings\org.eclipse.jdt.core.prefs
?????文件?????????465??2012-12-13?15:49??swfupload\.settings\org.eclipse.wst.common.component
?????文件?????????252??2012-12-13?15:49??swfupload\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2012-12-13?15:49??swfupload\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2012-12-13?15:49??swfupload\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2012-12-26?16:06??swfupload\WebRoot\
?????目錄???????????0??2012-12-13?15:49??swfupload\WebRoot\me
?????文件??????????36??2012-12-13?15:49??swfupload\WebRoot\me
?????目錄???????????0??2012-12-13?15:49??swfupload\WebRoot\WEB-INF\
?????目錄???????????0??2012-12-26?21:18??swfupload\WebRoot\WEB-INF\classes\
?????目錄???????????0??2012-12-26?21:18??swfupload\WebRoot\WEB-INF\classes\com\
?????目錄???????????0??2012-12-26?21:18??swfupload\WebRoot\WEB-INF\classes\com\sh\
?????目錄???????????0??2012-12-26?21:18??swfupload\WebRoot\WEB-INF\classes\com\sh\common\
?????文件????????3978??2012-12-26?21:18??swfupload\WebRoot\WEB-INF\classes\com\sh\common\FileUploadServlet.class
?????目錄???????????0??2012-12-13?15:50??swfupload\WebRoot\WEB-INF\lib\
?????文件???????53082??2012-12-13?15:50??swfupload\WebRoot\WEB-INF\lib\commons-fileupload-1.2.jar
?????文件???????87776??2012-12-13?15:50??swfupload\WebRoot\WEB-INF\lib\commons-io-1.3.2.jar
?????文件????????1088??2012-12-21?14:18??swfupload\WebRoot\WEB-INF\web.xm
?????目錄???????????0??2012-12-26?21:37??swfupload\WebRoot\css\
?????文件????????4201??2012-12-27?00:20??swfupload\WebRoot\css\swfupload-default.css
?????目錄???????????0??2012-12-27?14:07??swfupload\WebRoot\files\
?????目錄???????????0??2012-12-26?16:29??swfupload\WebRoot\images\
?????文件?????????788??2012-12-23?10:36??swfupload\WebRoot\images\background.png
?????文件????????8299??2012-12-23?10:36??swfupload\WebRoot\images\default.png
............此處省略14個文件信息
- 上一篇:UCI-iris數據集
- 下一篇:STEP 7 MicroWIN直接安裝補丁
評論
共有 條評論