資源簡介
uploadify上傳插件完整Demo,項目開發中被uploadify坑了一把,一怒之下寫了前后臺完整的示例,旨在徹底解決uploadify的問題!

代碼片段和文件信息
package?com.gsww.open.controller;
import?java.io.File;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.io.InputStream;
import?java.text.DecimalFormat;
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.FileUploadbase;
import?org.apache.commons.fileupload.ProgressListener;
import?org.apache.commons.fileupload.disk.DiskFileItemFactory;
import?org.apache.commons.fileupload.servlet.ServletFileUpload;
import?com.gsww.open.common.SpringContextHolder;
import?com.gsww.open.entity.sys.SysUserSession;
import?com.gsww.open.entity.upload.ShFileData;
import?com.gsww.open.service.upload.ShFileDataService;
import?com.gsww.open.util.StringHelper;
import?com.gsww.open.util.TimeHelper;
public?class?FileUploadServlet?extends?HttpServlet?{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?8382832509729035231L;
private?ShFileDataService?shFileDataService?=?SpringContextHolder.getBean(“shFileDataService“);
/**
?*?Constructor?of?the?object.
?*/
public?FileUploadServlet()?{
super();
}
/**
?*?Destruction?of?the?servlet.?
?*/
public?void?destroy()?{
super.destroy();?//?Just?puts?“destroy“?string?in?log
//?Put?your?code?here
}
/**
?*?The?doGet?method?of?the?servlet.?
?*
?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?get.
?*?
?*?@param?request?the?request?send?by?the?client?to?the?server
?*?@param?response?the?response?send?by?the?server?to?the?client
?*?@throws?ServletException?if?an?error?occurred
?*?@throws?IOException?if?an?error?occurred
?*/
public?void?doGet(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
doPost(requestresponse);
}
/**
?*?The?doPost?method?of?the?servlet.?
?*
?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?post.
?*?
?*?@param?request?the?request?send?by?the?client?to?the?server
?*?@param?response?the?response?send?by?the?server?to?the?client
?*?@throws?ServletException?if?an?error?occurred
?*?@throws?IOException?if?an?error?occurred
?*/
@Override
public?void?doPost(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
String?fileSize?=?““;
//?得到上傳文件的保存目錄,將上傳的文件存放于WEB-INF目錄下,不允許外界直接訪問,保證上傳文件的安全
//?E:/upload/data
?String?savePath?=
?this.getServletContext().getRealPath(“/WEB-INF/upload“);
//?上傳時生成的臨時文件保存目錄
?String?tempPath?=
?this.getServletContext().getRealPath(“/WEB-INF/temp“);
File?tmpFile?=?new?File(tempPath);
if?(!tmpFile.exists())?{
//?創建臨時目錄
tmpFile.mkdir();
}
//?消息提示
String?message?=?““;
try?{
//
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-27?17:26??uploadify兩個版本\
?????文件?????????298??2017-11-27?17:05??uploadify兩個版本\crossdomain.xm
?????文件????????9590??2017-11-27?17:25??uploadify兩個版本\FileUploadServlet.java
?????文件???????85367??2017-11-27?16:52??uploadify兩個版本\uploadify_flash.zip
?????文件???????41339??2017-11-27?17:23??uploadify兩個版本\uploadify_html5.zip
?????文件?????????359??2017-11-27?17:27??uploadify兩個版本\說明.txt
評論
共有 條評論