EXT 上传文件时加上fileUpload: true出错的问题。

来源:互联网 发布:苏州谢谢网络 编辑:程序博客网 时间:2024/05/23 17:49

Ext做文件上传的时候发现,如果上传成功后从后台取返回信息,出现错误。

Js代码 复制代码 收藏代码
  1. var importForm = new Ext.FormPanel({   
  2.         labelAlign:'right',    
  3.         buttonAlign:'right',    
  4.         frame:true,   
  5.         title: '',   
  6.         bodyStyle:'padding:5px 5px',   
  7.         width:450,   
  8.         url:'importAction.do?method=importAlarmRule',   
  9.         fileUpload: true,   
  10.         items: [{   
  11.              xtype: 'textfield',      
  12.              fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',      
  13.              name: 'importFile',   
  14.              width: 270,   
  15.              height:20,    
  16.              allowBlank:false,    
  17.              blankText: '<bean:message key="aloes.message.resource.import.file.select" />',     
  18.              inputType: 'file'//文件类型     
  19.            }],    
  20.              buttons: [{      
  21.                  text: '<bean:message key="button.save" />',                  
  22.                  handler: function() {      
  23.                      importForm.getForm().submit({      
  24.                          success: function(fileform, action){                     
  25.                         if(action.result.success == 'true'){   
  26.                                 Ext.Msg.alert('<bean:message key="info.header" />''<bean:message key="aloes.message.resource.import.success" />',function(){   
  27.                                     importWin.close();   
  28.                                 });                                    
  29.                             }else if(action.result.failure == 'formatError'){   
  30.                                 Ext.Msg.alert('Error''<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);   
  31.                             }   
  32.                          },   
  33.                          failure: function(){      
  34.                            Ext.Msg.alert('<bean:message key="message.error" />''<bean:message key="aloes.message.resource.import.failed" />');      
  35.                          }      
  36.                        });      
  37.                  }                                
  38.             },{      
  39.                  text: '<bean:message key="button.cancel" />',      
  40.                  handler: function() {   
  41.                        importWin.close();   
  42.                  }      
  43.             }]   
  44.         });   
  45.     var importWin = new Ext.Window({   
  46.                       id:'import-window',   
  47.                           title: '<bean:message key="aloes.message.resource.import" />',      
  48.                           closable:true,   
  49.                           width:460,   
  50.                           maximizable:false,   
  51.                           modal:true,   
  52.                           plain:true,          
  53.               items:[importForm]   
  54.                 });   
  55.      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 "

否则前台会报错。

原创粉丝点击