zoukankan      html  css  js  c++  java
  • JSP流的方式下载文件

    <%@ page import="java.io.*" %>
    <% 
    // example: 
    // <a href="download.JSP?path=img/&name=test.gif">download image</a> 

    String root 
    = getServletContext().getRealPath("/"); 
    String path 
    = request.getParameter("path"); 
    String name 
    = request.getParameter("name"); 
    System.out.println(root 
    + path + name);

    response.setContentType(
    "unknown"); 
    response.addHeader(
    "Content-Disposition""attachment;filename=\"" + name + "\""); 

    try 

    out.clear();
    out  
    =  pageContext.pushBody();
    OutputStream os 
    = response.getOutputStream(); 
    FileInputStream fis 
    = new java.io.FileInputStream(root + path + name); 

    byte[] b = new byte[1024]; 
    int i = 0

    while ( (i = fis.read(b)) > 0 ) 

    os.write(b, 
    0, i); 
    }
     

    fis.close(); 
    os.flush(); 
    os.close(); 
    }
     
    catch ( Exception e ) 

    }
     
    %>
  • 相关阅读:
    H5 WebSocket
    JS call()、apply()、bind()
    JS中this指向问题
    JS GET POST请求
    php 常用get post http请求
    php 开启redis
    egret接入华为快应用6004
    PHP生成公私钥,签名和验签
    JS数组去重
    Oracle第九课
  • 原文地址:https://www.cnblogs.com/ding0910/p/1207318.html
Copyright © 2011-2022 走看看