Jquery+swfupload+servlet实现多文件上传.doc_第1页
Jquery+swfupload+servlet实现多文件上传.doc_第2页
Jquery+swfupload+servlet实现多文件上传.doc_第3页
Jquery+swfupload+servlet实现多文件上传.doc_第4页
Jquery+swfupload+servlet实现多文件上传.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Jquery + swfupload+jsp、java 同时上传多张图片或文件导入swfupload的相关文件上传页面如下: base href= My JSP index.jsp starting page !- var swfu;window.onload = function () swfu = new SWFUpload(upload_url: /FileUploadServlet,/ File Upload Settingsfile_size_limit : 50 MB,/ 1000MBfile_types : *.*,/设置可上传的类型file_types_description : 所有文件,file_upload_limit : 10,file_queue_error_handler : fileQueueError,/选择文件后出错file_dialog_complete_handler : fileDialogComplete,/选择好文件后提交file_queued_handler : fileQueued,upload_progress_handler : uploadProgress,upload_error_handler : uploadError,upload_success_handler : uploadSuccess,upload_complete_handler : uploadComplete,/ Button Settingsbutton_image_url : /swfupload/images/SmallSpyGlassWithTransperancy_17x18.png,button_placeholder_id : spanButtonPlaceholder,button_width: 100,button_height: 18,button_text : 添加图片,button_text_style : .button font-family: Helvetica, Arial, sans-serif; font-size: 12pt; .buttonSmall font-size: 10pt; ,button_text_top_padding: 0,button_text_left_padding: 18,button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,button_cursor: SWFUpload.CURSOR.HAND,/ Flash Settingsflash_url : /swfupload/swfupload.swf,custom_settings : upload_target : divFileProgressContainer,/ Debug Settingsdebug: false /是否显示调试窗口);function startUploadFile()swfu.startUpload(); 上传文件的servlet:package com.hoy.servlet;import java.io.File;import java.io.IOException;import java.util.Enumeration;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import mons.io.FilenameUtils;import mons.lang.StringUtils;import mons.lang.time.DateFormatUtils;import com.oreilly.servlet.MultipartRequest;import com.oreilly.servlet.multipart.FileRenamePolicy;/* * author huangshuang * version 2011-5-1 */public class FileUploadServlet extends HttpServlet private static final long serialVersionUID = -3096800116651263134L;private String fileSizeLimit;private File oldFile;public void init(ServletConfig config) throws ServletException this.fileSizeLimit = config.getInitParameter(fileSizeLimit);System.out.println(fileSizeLimit+aa);public void destroy() this.fileSizeLimit = null;super.destroy();class MyFileRenamePolicy implements FileRenamePolicy public File rename(File file) oldFile = file;String fileSaveName = StringUtils.join(new String java.util.UUID.randomUUID().toString(), .,FilenameUtils.getExtension(file.getName() );File result = new File(file.getParentFile(), fileSaveName);return result;public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException System.out.println(- BEGIN DOPOST -);HttpSession session = request.getSession();/upload/mailString uploadDir = upload + File.separatorChar + mail + File.separatorChar;/String autoCreatedDateDirByParttern = yyyy + File.separatorChar + MM + File.separatorChar + dd+ File.separatorChar;String autoCreatedDateDir = DateFormatUtils.format(new java.util.Date(), autoCreatedDateDirByParttern);String ctxDir = session.getServletContext().getRealPath(String.valueOf(File.separatorChar);if (!ctxDir.endsWith(String.valueOf(File.separatorChar) ctxDir = ctxDir + File.separatorChar;File savePath = new File(ctxDir + uploadDir + autoCreatedDateDir);if (!savePath.exists() savePath.mkdirs();System.out.println(savePath.getName()+=1);String saveDirectory = ctxDir + uploadDir + autoCreatedDateDir;if (StringUtils.isBlank(this.fileSizeLimit) this.fileSizeLimit = 80;/ 100MSystem.out.println(fileSizeLimit+bb);int maxPostSize = Integer.parseInt(this.fileSizeLimit) * 1024 * 1024;String encoding = UTF-8;System.out.println(aaa);FileRenamePolicy rename = new MyFileRenamePolicy();MultipartRequest multi = null;try System.out.println(test);multi = new MultipartRequest(request, saveDirectory, maxPostSize, encoding, rename);System.out.println(oldFile.getName()+=2); catch (IOException e) e.printStackTrace();return;/ Enumeration files = multi.getFileNames();while (files.hasMoreElements() String name = (String) files.nextElement();File f = multi.getFile(name);System.out.println(f.getName();if (f != null) String fileName = multi.getFilesystemName(name);String lastFileName = saveDirectory + + fileName;String fileSavePath = uploadDir + autoCreatedDateDir + fileName;System.out.println(SimpleUploaderServlet);System.out.println(: + lastFileName);System.out.println(: + fileSavePath);response.getWriter().print(fileSavePath);System.out.println(- END DOPOST -);public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException this.doPost(request, response);public String getFileSizeLimit() return fileSizeLimit;public void setFileSizeLimit(String fileSizeLimit) this.fileSizeLimit = fileSizeLimit;删除文件的servlet:package com.hoy.servlet;import java.io.IOException;import java.io.PrintWriter;import java.io.File;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class DeleteFileServlet extends HttpServlet /* * Constructor of the object. */public DeleteFileServlet() 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 /* * 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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论