文件写出web头部设置

 if(rpt!=null){
    	   response.reset();
    	   boolean isDownload = "download".equalsIgnoreCase(request.getParameter("mode"));
           String mode = isDownload ? "attachment" : "inline";
           response.setContentType("APPLICATION/DOWNLOAD");           
           response.setHeader("Content-Disposition",mode+";filename=" +downloadFileName+"."+getReportExtension(reportFormat));          
           response.setHeader("Pragma", "public");
           response.setDateHeader("Expires", 0);
           response.setHeader("Cache-Control","must-revalidate,post-check=0,pre-check=0");
           try {
				OutputStream os = null;
				response.setContentLength(rpt.length);
				os = response.getOutputStream();
				os.write(rpt);
				os.close();
				response.flushBuffer();
				return null;
			} catch (Exception e) {
				e.printStackTrace();
			}     
       }

 rpt为要输出文件的字节数组:byte[] rpt=xxx;

说明:

1、response.reset();        清除buffer

2、response.setHeader("Content-disposition","attachment;filename="+new String(str.getBytes("gb2312"),"iso8859-1")); //客户使用目标另存为对话框保存指定文件

3、response.setHeader("Content_Length",length);设置头文件的长度为指定文件的长度

你可能感兴趣的:(Web,cache,OS)