亚洲AVI,黑人巨茎大战欧美白妇,初高中生洗澡自慰高清网站,欧美日韩无砖专区一中文字

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

使用Java實現(xiàn)文件點擊沒反應(yīng)的方法

這篇文章主要介紹使用Java實現(xiàn)文件點擊沒反應(yīng)的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)長期為超過千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為競秀企業(yè)提供專業(yè)的網(wǎng)站制作、成都做網(wǎng)站,競秀網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

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)的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


當前題目:使用Java實現(xiàn)文件點擊沒反應(yīng)的方法
分享URL:http://news.spvevtbd.cn/article/gojjoj.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP