Ext.ux.dialog common-fileupload 整合[收]

Ext.onReady(function() { 
var dialog = new Ext.ux.UploadDialog.Dialog(null,
{
autoCreate : true,
closable : true,
collapsible : false,
draggable : true,
minWidth : 500,
minHeight : 200,
width : 400,
height : 350,
proxyDrag : true,
resizable : true,
//permitted_extensions : ['JPG', 'jpg', 'jpeg', 'JPEG', 'GIF', 'gif','doc','xls'],
constraintoviewport : true,
title : '文件上传的例子',
url : '/NewSMS/fileupload',
reset_on_hide : false,
allow_close_on_upload : true
});
dialog.show('my-dlg');
});


package com.hiber;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;

public class Upload extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 7440302204266787092L;

String uploadPath = "d:\\"; // 用于存放上传文件的目录

String tempPath = "d:\\tmp\\"; // 用于存放临时文件的目录

public Upload(){
super();
System.out.println("文件上传启动");
}

public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

public void init() throws ServletException {
System.out.println("文件上传初始化");
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
System.out.println("开始进行文件上传");
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb
fu.setRepositoryPath(tempPath); // 设置临时目录
List fileItems = fu.parseRequest(request); // 得到所有的文件:
Iterator i = fileItems.iterator();
// 依次处理每一个文件:
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();// 获得文件名,这个文件名包括路径:
if (fileName != null) {
// 在这里可以记录用户和文件信息
// 此处应该定义一个接口(CallBack),用于处理后事。
// 写入文件a.txt,你也可以从fileName中提取文件名:
fi.write(new File(uploadPath + "a.txt"));
}
}
response.setContentType("text/html;charset=utf-8");
response.getWriter().print("{success:true,msg:'成功'}");
// 跳转到上传成功提示页面
} catch (Exception e) {
response.getWriter().print("{success:flase,msg:'失败'}");
// 可以跳转出错页面
}

}
}
Configuration. Most configuration options are inherited from Ext.Window (see ExtJs docs). The added ones are: url - the url where to post uploaded files. base_params - additional post params (default to {}). permitted_extensions - array of file extensions which are permitted to upload (default to []). reset_on_hide - whether to reset upload queue on dialog hide or not (default true). allow_close_on_upload - whether to allow hide/close dialog during upload process (default false). upload_autostart - whether to start upload automaticaly when file added or not (default false). post_var_name - uploaded data POST variable name (defaults to 'file'). Events. filetest - fires before file is added into the queue, parameters: dialog - reference to dialog filename - file name If handler returns false then file will not be queued. fileadd - fires when file is added into the queue, parameters: dialog - reference to dialog filename - file name fileremove - fires when file is removed from the queue, parameters: dialog - reference to dialog filename - file name record - file record resetqueue - fires when upload queue is resetted, parameters: dialog - reference to dialog beforefileuploadstart - fires when file as about to start uploading: dialog - reference to dialog filename - uploaded file name record - file record If handler returns false then file upload will be canceled. fileuploadstart - fires when file has started uploading: dialog - reference to dialog filename - uploaded file name record - file record uploadsuccess - fires when file is successfuly uploaded, parameters: dialog - reference to dialog filename - uploaded file name data - js-object builded from json-data returned from upload handler response. record - file record uploaderror - fires when file upload error occured, parameters: dialog - reference to dialog filename - uploaded file name data - js-object builded from json-data returned from upload handler response. record - file record uploadfailed - fires when file upload failed, parameters: dialog - reference to dialog filename - failed file name record - file record uploadcanceled - fires when file upload canceled, parameters: dialog - reference to dialog filename - failed file name record - file record uploadstart - fires when upload process starts, parameters: dialog - reference to dialog uploadstop - fires when upload process stops, parameters: dialog - reference to dialog uploadcomplete - fires when upload process complete (no files to upload left), parameters: dialog - reference to dialog Public methods Better go see the source. I18n. The class is ready for i18n, override the Ext.ux.UploadDialog.Dialog.prototype.i18n object with your language strings, or just pass i18n object in config. Server side handler. The files in the queue are posted one at a time, the file field name is 'file'. The handler should return json encoded object with following properties:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值