中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

jsp 文件安全下載

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DownLoadServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String path = "C:/file";
        String fileName = request.getParameter("filename");
        File file = new File(path + "/" + fileName);
        //如果文件存在
        if (file.exists()) {
            //設(shè)置響應(yīng)類型及響應(yīng)頭
            response.setContentType("application/x-msdownload");
            response.addHeader("Content-Disposition", "attachment; filename=\""
                    + fileName + "\"");
            //讀取文件
            InputStream inputStream = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(inputStream);
            byte[] bytes = new byte[1024];
            ServletOutputStream outStream = response.getOutputStream();
            BufferedOutputStream bos = new BufferedOutputStream(outStream);
            int readLength = 0;
            while ((readLength = bis.read(bytes)) != -1) {
                bos.write(bytes, 0, readLength);
            }
            //釋放資源
            inputStream.close();
            bis.close();
            bos.flush();
            outStream.close();
            bos.close();
        }
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:UITextView 文本輸入框

下一篇:UIPickerView 滾動(dòng)選擇器