• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 用Jsp來實現文件下載功能的幾種方式

    發表于:2008-04-29來源:作者:點擊數: 標簽:Jsp文件下載功能
    關鍵字:Jsp 1.最直接最簡單的,方式是把文件地址直接放到html頁面的一個鏈接中。這樣做的缺點是把文件在服務器上的路徑暴露了,并且還無法對文件下載進行其它的控制(如權限)。這個就不寫示例了。 2.在服務器端把文件轉換成輸出流,寫入到response,以re
    關鍵字:Jsp

    1.最直接最簡單的,方式是把文件地址直接放到html頁面的一個鏈接中。這樣做的缺點是把文件在服務器上的路徑暴露了,并且還無法對文件下載進行其它的控制(如權限)。這個就不寫示例了。

    2.在服務器端把文件轉換成輸出流,寫入到response,以response把文件帶到瀏覽器,由瀏覽器來提示用戶是否愿意保存文件到本地。(示例如下)

    <%
     response.setContentType(fileminitype);
     response.setHeader("Location",filename);
     response.setHeader("Cache-Control", "max-age=" + cacheTime);
         //filename應該是編碼后的(utf-8)
     response.setHeader("Content-Disposition", "attachment; filename=" + filename); 
     
     response.setContentLength(filelength);
     OutputStream outputStream = response.getOutputStream();
     InputStream inputStream = new FileInputStream(filepath);
     byte[] buffer = new byte[1024];
     int i = -1;
     while ((i = inputStream.read(buffer)) != -1) {
      outputStream.write(buffer, 0, i);
      }
     outputStream.flush();
     outputStream.close();
     inputStream.close();
     outputStream = null;
    
    %>

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>