extjs 實現下載功能

來源:互聯網
上載者:User

標籤:使用   io   資料   art   ar   cti   代碼   new   

糾結了好久,終於實現了extjs的下載功能,其實下載的原理很簡單,就是給介面一個按鈕,讓按鈕觸發後台action,將地址返回給前台。具體實現如下。

//extjs代碼,頁面

var btn_out_user = new Ext.Button({  text : ‘匯出excel‘,  iconCls : ‘icon-del‘,  handler : function() {  Ext.Msg.show({   title:‘確認匯出‘,      msg: ‘您確定匯出資料?‘,      buttons: Ext.Msg.YESNO,      width : 250,      fn: function(btn){    if(btn==‘yes‘){              Ext.MessageBox.wait(‘正在匯出資料, 請稍侯 ...‘, ‘提示‘);                Ext.Ajax.request({              url : ‘outShopInfoAction.action‘,       success : function(resp, ops){        var obj = Ext.decode(resp.responseText);             window.parent.document.location = obj.path;//將地址賦值        Ext.MessageBox.updateProgress(1); //設定進度條               Ext.MessageBox.hide();  //關閉進度條        ds_user.load({params : {start : 0,limit : 20}});       },       failure : function() {        Ext.MessageBox.updateProgress(1);                Ext.MessageBox.hide();          Ext.Msg.show({         title : ‘錯誤提示‘,         msg : ‘刪除時發生錯誤!‘,         width : 200,         buttons : Ext.Msg.OK,         icon : Ext.Msg.ERROR        });      }     });    }      },       icon: Ext.MessageBox.QUESTION  });  } });

後台調用程式如下:

 public void out() throws Exception{      String outPath = "../upload/test.xls";    this.getResponse().getWriter().write("{‘path‘ : ‘"+outPath+"‘}");  }

 
在這裡要求會使用json的資料傳遞,在背景程式中,傳遞一個參數path,它的值是:String outPath = "../upload/test.xls"。前台負責接收這個參數,通過參數名稱,取得這個參數的值。

var obj = Ext.decode(resp.responseText); window.parent.document.location = obj.path;

通過以上的方法,可以在後台任意給前台推送值。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.