ExtJS 多文件上传

前台实现:

ExtJS MVC 上传文件button响应事件里面的:

	//multi file upload  插件
		var panel = Ext.create('Ext.ux.uploadPanel.UploadPanel', {
					header : false,
					addFileBtnText : '选择日志文件...',
					uploadBtnText : '上传',
					removeBtnText : '移除所有',
					cancelBtnText : '取消上传',
					file_size_limit : 100,// MB
					width : 750,
					height : 300,
					flash_url : "swfupload/swfupload.swf",
					flash9_url : "swfupload/swfupload_fp9.swf",
					upload_url : path + '/projectmanager/UploadAction.action'
				});
		win = Ext.widget('window', {
					title : '日志文件上传',
					closeAction : 'destroy',
					layout : 'fit',
					resizable : false,
					modal : true,
					items : panel
				});
		win.show();

后台实现action:

public class UploadAction  extends Struts2ActionSupport {

	    private File   Filedata;
	    private String FiledataFileName;
	    private String FiledataContentType;
	    //前台用户修改后的文件名
	    private String newFileName;
	    
	    private String savePath;
	    
		public String getSavePath() {
			return savePath;
		}
		public void setSavePath(String savePath) {
			this.savePath = savePath;
		}
		public File getFiledata() {
			return Filedata;
		}
		public String getFiledataFileName() {
			return FiledataFileName;
		}
		public String getFiledataContentType() {
			return FiledataContentType;
		}
		public void setFiledata(File filedata) {
			Filedata = filedata;
		}
		public void setFiledataFileName(String filedataFileName) {
			FiledataFileName = filedataFileName;
		}
		public void setFiledataContentType(String filedataContentType) {
			FiledataContentType = filedataContentType;
		}
		
		//文件读取和日志数据插入到数据库
		public String fileUpLoad() throws Exception{
			InputStream  is = new FileInputStream(Filedata);
			String root = ServletActionContext.getServletContext().getRealPath(savePath); 
			
			File deskFile = new File(root,newFileName);
			OutputStream os = new FileOutputStream(deskFile);
			byte[] buffer = new byte[1024];
			int length = 0;
			while((length =is.read(buffer))!=-1){
				os.write(buffer,0,length);
				
			}
			os.close();
			is.close();
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/xml;charset=utf-8");
			response.getWriter().write("{success:true}");
			
			return null;
		}
		public String getNewFileName() {
			return newFileName;
		}
		public void setNewFileName(String newFileName) {
			this.newFileName = newFileName;
		}
}


版权声明:本文为u010506262原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。