Ext做文件上传的时候发现,如果上传成功后从后台取返回信息,出现错误。
- var importForm = new Ext.FormPanel({
- labelAlign:'right',
- buttonAlign:'right',
- frame:true,
- title: '',
- bodyStyle:'padding:5px 5px',
- width:450,
- url:'importAction.do?method=importAlarmRule',
- fileUpload: true,
- items: [{
- xtype: 'textfield',
- fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',
- name: 'importFile',
- width: 270,
- height:20,
- allowBlank:false,
- blankText: '<bean:message key="aloes.message.resource.import.file.select" />',
- inputType: 'file'//文件类型
- }],
- buttons: [{
- text: '<bean:message key="button.save" />',
- handler: function() {
- importForm.getForm().submit({
- success: function(fileform, action){
- if(action.result.success == 'true'){
- Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){
- importWin.close();
- });
- }else if(action.result.failure == 'formatError'){
- Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);
- }
- },
- failure: function(){
- Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />');
- }
- });
- }
- },{
- text: '<bean:message key="button.cancel" />',
- handler: function() {
- importWin.close();
- }
- }]
- });
- var importWin = new Ext.Window({
- id:'import-window',
- title: '<bean:message key="aloes.message.resource.import" />',
- closable:true,
- width:460,
- maximizable:false,
- modal:true,
- plain:true,
- items:[importForm]
- });
- importWin.show();
var importForm = new Ext.FormPanel({ labelAlign:'right', buttonAlign:'right', frame:true, title: '', bodyStyle:'padding:5px 5px', width:450, url:'importAction.do?method=importAlarmRule', fileUpload: true, items: [{ xtype: 'textfield', fieldLabel: '<bean:message key="aloes.message.resource.import.file" />', name: 'importFile', width: 270, height:20, allowBlank:false, blankText: '<bean:message key="aloes.message.resource.import.file.select" />', inputType: 'file'//文件类型 }], buttons: [{ text: '<bean:message key="button.save" />', handler: function() { importForm.getForm().submit({ success: function(fileform, action){ if(action.result.success == 'true'){ Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){ importWin.close(); }); }else if(action.result.failure == 'formatError'){ Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info); } }, failure: function(){ Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />'); } }); } },{ text: '<bean:message key="button.cancel" />', handler: function() { importWin.close(); } }] }); var importWin = new Ext.Window({ id:'import-window', title: '<bean:message key="aloes.message.resource.import" />', closable:true, width:460, maximizable:false, modal:true, plain:true, items:[importForm] }); importWin.show();
后台的java代码往前台送数据的时候:
resultStr.append("{'failure':'false','success':'true'}");
response.setContentType(" text/html;charset=utf-8 ");
response.getWriter().print(resultStr);
contentType必须为:" text/html;charset=utf-8 "
而不能为:" text/xml;charset=utf-8 "
否则前台会报错。