/** 通常我们在使用EXTJS,有一定的程度让客户体验度更佳.所以我们在做上传功能时,我们是使用Ext.Window组件, * 在Window中的item属性装载我们的FormPanel,而在FormPanel有个非常重要的属性是fileUpload,当这个属性为真时, * 就会声明当前FORM是一个带上传的FORM,其实就是把contentType改为“multipart/form-data”。而在FormPanel * 中我们也同样需要给一个items,里面的inputType属性为file,这样便可以出现我们的文件上传. **/ var form1 = new Ext.form.FormPanel({ enctype:'multipart/form-data', fileUpload: true, frame:true, labelWidth:80, defaults: {width: 150}, defaultType: 'textfield', items: [{ allowBlank:false,//对文件选择框为空时的验证 blankText:"所选文件为空,请确认", fieldLabel: '模板选择', name:'uploadFile', height: 18, anchor:'90%', inputType:'file' }], buttons: [{ text: '保存', handler: function(){ if(form1.getForm().isValid()){ form1.getForm().submit({ url: 'semis/ZDDMBManage/uploadFile.action?bhsblxId='+curttenId.substring(4)+'&zddmbId='+tempMBID, waitMsg: '文件上传中......', success: function(form1,action){ Ext.MessageBox.alert('提示', '文件上传成功'); addWin.hide(); ds.load({ params:{ bhsblxId:curttenId.substring(4) } }); }, failure:function(form1,action){ if(action.failureType==Ext.form.Action.SERVER_INVALID){ Ext.MessageBox.alert('提示', '文件校验失败'); }else{ Ext.MessageBox.alert('提示', '无法访问后台'); } } }); } } },{ text: '取消', handler: function(){ addWin.hide(); ds.load({ params:{ bhsblxId:curttenId.substring(4) } }); } }] }); addWin = new Ext.Window({ title:'添加模板', autoShow:true, closable:true, closeAction:'hide', width:500, height:100, plain:true, resizable:false, items:[ form1 ] }); addWin.show(); /** * 此功能是采用struts2+extJs来实现的。之前也在尝试使用extjs给出的范例来实现。而没有成功。 * extjs范例:http://www.extjs.com/deploy/dev/examples/form/file-upload.html * 如果大家有什么更好的方法,非常愿意与各位朋友交流 **/