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),日志也不報錯,下面我們一起來看一下吧。
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); } });
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(); }
window.open('/yjy/training/TrainingTimeAction.do?method=downLoadAttchById&timeId=' + timeids);
以上所述是小編給大家介紹的Java實現(xiàn)文件點擊沒反應(yīng)的方法,希望對大家有所幫助,非常感謝大家對扣丁學(xué)堂小編的支持!
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>