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

java實(shí)現(xiàn)文件下載

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

文件下載

輸出內(nèi)容包含 

1.文件內(nèi)容:content

2. 輸出類型 contentType : application/msword

3 文件長(zhǎng)度: contentLength: content.length

4.文件名稱:

    /** 
         * 下載文件 
         * @param request 
         * @param response 
         * @throws IOException 
         * @throws InterruptedException 
         */  
        public void downloadDoc(HttpServletRequest request,HttpServletResponse response) throws IOException, InterruptedException  
        {  
            String id=request.getParameter("id")==null?"0":request.getParameter("id");  
            DocumentAtt documentAtt=documentAttDao.findById(id); //業(yè)務(wù)對(duì)象根據(jù)實(shí)際情況修改  
            byte [] content=documentAtt.getFiles();  
            OutputStream os=response.getOutputStream();  
            InputStream is=new  ByteArrayInputStream(content);   
            response.setContentType(documentAtt.getFiletype());//<span style="font-family: Arial, Helvetica, sans-serif;">可不設(shè)置</span>  
            response.setContentLength(content.length);//可不設(shè)置  
            response.setHeader("Content-Disposition","attachment;filename="+new String(documentAtt.getName().getBytes("GBK"),"ISO-8859-1"));  
            byte[] buffer = new byte[4000];  
            int length;  
            while((length = is.read(buffer)) != -1){  
                  os.write(buffer,0,length);  
            }  
                
            is.close();  
            os.close();  
        }  


標(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)系。

上一篇:javascript計(jì)算兩個(gè)日期之間相差多少天

下一篇:java日期遍歷