欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂Java開發(fā)實現(xiàn)文件點擊沒反應(yīng)的源碼方法詳解

2018-07-26 14:16:28 1101瀏覽

今天扣丁學(xué)堂Java培訓(xùn)老師給大家準(zhǔn)備了一篇關(guān)于Java實現(xiàn)文件點擊沒反應(yīng)的方法及具體源碼詳解,比如jsp頁面鏈接,點擊訪問action用IO流去下載服務(wù)器上的文件,問題是任憑怎么點擊都沒反應(yīng),日志也不報錯,下面我們一起來看一下吧。



前臺ajax代碼

Ext.Ajax.request({
url : '/yjy/training/TrainingTimeAction.do?method=downLoadAttchById',
params : {
timeId : timeids
},
success : function(response,options){
var result = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert("下載成功");
},
failure :function(response,options){
var result = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert("下載失敗"+result.message);
}
});

后臺action代碼

String timeId = request.getParameter("timeId");
      String sql = "select doc_name from CPER.EHRTRAIN_item_DOCUMENT where item_id = ?";
      DbHelper dbHelper = new DbHelper();
      Object[] params = new Object[]{timeId};
      String fileName = (String)dbHelper.runSQLScalar(sql, params);
      String filePath = ServerPathUtil.getPathRoot()+"WEB-INF/cache/train_item_file/train_item_file_"+timeId+"/"+fileName;
      File file = new File(filePath);
      if(!file.exists()){
        logger.debug("文件不存在");
        throw new IOException("the file not exists");
      }
      response.setContentLength((int) file.length());
      OutputStream o = response.getOutputStream();
      byte b[] = new byte[5000];
      //response.setContentType("application/x-msdownload");
      response.setContentType("application/vnd.ms-excel");
      response.setContentLength((int)file.length());
      response.setHeader("Content-Disposition","attachment; filename="+fileName);
      FileInputStream in = new FileInputStream(file);
      int n; 
      while ((n = in.read(b)) != -1) {
        o.write(b, 0, n);
      }
      in.close();
    }catch(Exception e){
      e.printStackTrace();
    }

解決方法:文件的下載,在前臺請求的時候,只能是form表單請求,或者用window.open的方式,最后我采用了window.open的方式

window.open('/yjy/training/TrainingTimeAction.do?method=downLoadAttchById&timeId=' + timeids);

注:采用這種方式頁面會彈出一個空白窗口,下載之后窗口自動關(guān)閉,如果不想顯示這個窗口,使用form提交的方式

以上所述是小編給大家介紹的Java實現(xiàn)文件點擊沒反應(yīng)的方法,希望對大家有所幫助,非常感謝大家對扣丁學(xué)堂小編的支持!

扣丁學(xué)堂微信公眾號



【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】



查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>

標(biāo)簽: JavaEE視頻教程 JavaEE培訓(xùn) JavaEE開發(fā)工程師 Java培訓(xùn)

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部