Extjs+Struts实现文件文件上传问题集锦

来源:互联网 发布:淘宝金城70改装效果图 编辑:程序博客网 时间:2024/05/29 15:09

1.上传文件点击提交时firebug查看,出现以下错误:Missing } in XML expression

   问题:使用firedebug跟踪了一下返回的数据, 发现responseText中被加上了<pre></pre>标签,

   浏览一下源代码,发现Ext.form.Action.Submit提交请求是用Ext.Ajax组件进行数据传输的. Ext.form.Action.Submit部分源代码如下:

function formSubmit(){ 
   if (form.getForm().isValid()) { //验证表单填写的数据是否有效 
    form.getForm().submit({     //调用basicForm的submit方法 
     waitTitle : '提示',//标题 
     waitMsg : '正在提交数据请稍后...',//提示信息 
     url : 'eidtBooktype.action',   //将要把表单发送到哪里 
     method : 'post',   //指定发送方式 
     params : 'booktype', //携带的参数 
     success : function(form, action){  //form指这个表单 action指返回内容 
      var flag=action.result.msg; 
      window.returnValue='SUCC'; 
      Ext.Msg.alert('提示',flag,function(){ 
       window.close(); 
      }); 
     }, 
     failure : function(form,action) { 
      var flag=action.result.msg; 
      Ext.Msg.alert('操作', flag); 
     } 
    }); 
   } 
}

解决方法:因为在processResponse函数处理数据时出现异常,重写processResponse方法就OK了.在你所使用的JS中加入如下一段代码:

    Ext.override(Ext.form.Action.Submit,{ 
    // private 
    processResponse : function(response){ 
        this.response = response; 
        //增加下面几句代码就OK啦 
        //////////////////////// 
        var data = response.responseText; 
        if(data.indexOf('<pre>') != -1) { 
          response.responseText = data.substring(5, data.length-6); 
          this.response = Ext.util.JSON.decode(response.responseText); 
        }     
        ///////////////////////////      
        if(!response.responseText){ 
            return true; 
        } 
        this.result = this.handleResponse(response); 
        return this.result; 
    } 
});

2.   (1) 上传文件完成后,一直执行failure部分,Extjs得不到前台的返回数据

                Ext.MessageBox.alert("success action="+action);---->输出为:[object Object]

                Ext.MessageBox.alert("success action.result="+action.result);----->输出为:[object Object]

                Ext.MessageBox.alert("success action.result.success="+action.result.success)---->输出为:undefined

       (2) missing ) in parenthetical  TTP Status 500

       (3) missing ] after element list

       问题:后台返回值有问题,struts配置文件错误。

       解决方法:正确配置返回参数。

原创粉丝点击