最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用Java實現(xiàn)文件點擊沒反應的方法

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

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

jsp頁面鏈接,點擊訪問action用IO流去下載服務器上的文件,問題是任憑怎么點擊都沒反應,日志也不報錯。

前臺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);

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

以上是“使用Java實現(xiàn)文件點擊沒反應的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


當前名稱:使用Java實現(xiàn)文件點擊沒反應的方法
當前地址:http://fisionsoft.com.cn/article/gojjoj.html