首页 > 代码库 > ExtJS:文件上传实例
ExtJS:文件上传实例
ExtJS:文件上传实例
var ext_dateFormat = ‘Y-m-d H:i:s‘; var dateFormat = ‘yyyy-MM-dd HH:mm:ss‘; var date = new Date(); Ext.onReady(function() { var fifp =Ext.create(‘Ext.form.Panel‘, { renderTo: ‘fi-form‘, width: 500, frame: true, title: ‘文件上传‘, bodyPadding: ‘10 10 0‘, defaults: { anchor: ‘100%‘, allowBlank: false, msgTarget: ‘side‘, labelWidth: 80 }, items: [{ xtype: ‘textfield‘, fieldLabel: ‘样品编号‘, id:‘finfo‘, name:‘finfo‘ },{ xtype: ‘container‘, layout: ‘hbox‘, items: [{ xtype: ‘textfield‘, fieldLabel: ‘当前经度‘, id:‘flongitude‘, name:‘flongitude‘, msgTarget: ‘side‘, allowBlank: false, labelWidth: 80 }, { xtype: ‘textfield‘, fieldLabel: ‘当前纬度‘, id:‘flatitude‘, name:‘flatitude‘, msgTarget: ‘side‘, allowBlank: false, labelWidth: 80 }] },{ xtype : ‘textfield‘, fieldLabel : ‘上传时间‘, id : ‘ftime‘, name : ‘ftime‘, // yyyy-MM-dd HH:mm:ss value : Ext.Date.format(new Date(date.getFullYear(),date.getMonth(),date.getDate(), date.getHours(),date.getMinutes(),date.getSeconds()), ext_dateFormat), listeners : { ‘focus‘ : function() { WdatePicker({ dateFmt : dateFormat }); } } },{ xtype: ‘filefield‘, id: ‘fiupload‘, emptyText: ‘请点击右边按钮选择文件!‘, fieldLabel: ‘选择文件‘, name: ‘fiupload‘, buttonText: ‘浏览文件‘, buttonConfig: { iconCls: ‘upload-icon‘ } }], buttons: [{ text: ‘保存文件‘, handler: function(){ var fiform = this.up(‘form‘).getForm(); if(fiform.isValid()){ fiform.submit({ type : ‘ajax‘, url: ‘files/addData.action‘, method : "POST", waitMsg: ‘ 正在上传,请稍候...‘, success: function(form, action) { Ext.Msg.alert(‘Success‘,‘文件上传成功!‘); }, failure:function(form, action) { Ext.Msg.alert("Failure","文件上传失败"); } }); } } },{ text: ‘重新上传‘, handler: function() { this.up(‘form‘).getForm().reset(); } }] }); });
后台处理核心类方法:
private static final int BUFFER_SIZE = 16 * 1024; public String addData() throws Exception { Timestamp ts = new Timestamp(System.currentTimeMillis()); SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");// 设置日期格式 ts = Timestamp.valueOf(this.ftime); System.out.println(ts); String nowtime = df.format(new Date()); System.out.println("uploadFileName = " + this.fiuploadFileName); System.out.println("uploadContentType = " + this.fiuploadContentType); System.out.println(nowtime); // upload -- wapps 下面的文件夹,用来存放图片 String toSrc = http://www.mamicode.com/ServletActionContext.getServletContext().getRealPath(>ExtJS:文件上传实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。