在做的一个项目里面希望提供文件的上传于下载,下载的需求是选中GridPanel中的一行,点击下载,会弹出“另存为..”对话框供,用window.open()会提示报错,请问ExtJS的代码该怎么写。DownloadExcelFiles = function(){
    var record = grid1.getSelectionModel().getSelections();//grid1为已定义的GridPanel
    if (record.length == 0) {
        Ext.MessageBox.alert('系统提示信息', '请选择你要下载的文件!');
    }
    else 
        if (record.length > 1) {
            Ext.MessageBox.alert('系统提示信息', '一次只能下载一个文件!')
        }
        else 
            if (record.length == 1) {
                var _filename = ' ';
var _filepath = 'E:\\work\\temp\\'; 
_filename = _filepath + record[0].get('name');
alert(_filename);
                window.open(_filename, '_blank', 
'width=1,height=1,toolbar=no,menubar=no,location=no');//报错,提示“拒绝访问”
            }
}

解决方案 »

  1.   

    网上提到用ExtJS无法实现文件下载,请问下面的代码如何实现?Ext.Ajax.request({
        url:'getPath.action',
        success:function(res){
            var obj = Ext.decode(res.responseText);
            //console.log(obj);//可以到火狐的firebug下面看看obj里面的结构
            //加入getPath返回的json为{'path':'upload/abc.jpg'}
            window.location.href = obj.path;//这样就可以弹出下载对话框了
        }
    });
      

  2.   

    采用Ext.window的方法
    var win = new top.Ext.Window({
        items : [{ html :_filename}]
    });
    win.show(); 
      

  3.   

    用Ext.window只能弹出一个窗体吧,无法下载的
      

  4.   


    window.location.href = obj.path;//这样就可以弹出下载对话框了
    跳转到一个普通的jsp或html页面,页面上提供下载地址或下载操作
      

  5.   

     var _filepath = 'E:\\work\\temp\\'; 这句应该写成服务端的虚拟路径
      

  6.   


    DownloadExcelFiles = function() {
    var records = grid1.getSelectionModel().getSelections(); 
    if (records.length == 0) {
            Ext.MessageBox.alert('系统提示信息', '请选择你要下载的文件!');
        }
        else 
            if (records.length > 1) {
                Ext.MessageBox.alert('系统提示信息', '一次只能下载一个文件!');
            } else {
    var _filename = ' ';
    var _filepath = 'E:\\work\\temp\\'; 
    _filename = _filepath + records[0].get('name');
            Ext.Ajax.request({
    url: GURLBase+"/EXEC/"+GTrackID+"/"+GAppID+"?op=downloadimpfile&Format=xls&SessionId="+GMySession,
    params : {
    filename: _filename,
    filepath: _filepath  //下载路径
          },
          method: 'POST',
      success: function (response, config) {
       var obj = Ext.decode(response.responseText);
    //window.location.href = obj.path;
    alert(obj);
    alert("filename:"+_filename);
    //window.open(_url,'_self','width=1,height=1,toolbar=no,menubar=no,location=no'); 
      },
          failure: function ( result, request) { 
                Ext.MessageBox.alert('FAILURE', '下载操作失败!');  
          }        
    })
      }
    };
      

  7.   

    楼主 问题解决了吗?可否分享下,我也是初学,需要Extjs提供文件下载;
      

  8.   

    我用了这个怎么不行呀 ,struts.xml是怎么配置的,action中怎么写呀 ? 楼主!