日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

java文件没反应_Java实现文件点击没反应的方法

發(fā)布時(shí)間:2025/3/19 java 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java文件没反应_Java实现文件点击没反应的方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

jsp頁(yè)面鏈接,點(diǎn)擊訪問(wèn)action用IO流去下載服務(wù)器上的文件,問(wèn)題是任憑怎么點(diǎn)擊都沒(méi)反應(yīng),日志也不報(bào)錯(cuò)。

前臺(tái)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);

}

});

后臺(tái)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();

}

解決方法:文件的下載,在前臺(tái)請(qǐng)求的時(shí)候,只能是form表單請(qǐng)求,或者用window.open的方式,最后我采用了window.open的方式

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

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

總結(jié)

以上所述是小編給大家介紹的Java實(shí)現(xiàn)文件點(diǎn)擊沒(méi)反應(yīng)的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)網(wǎng)站的支持!

總結(jié)

以上是生活随笔為你收集整理的java文件没反应_Java实现文件点击没反应的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。