/*********************************设置浏览器无缓存******************************/
//resp.setHeader:发送一个报头,告诉浏览器当前页面不进行缓存,每次访问的时间必须从服务器上读取最新的数据
//no-cache:客户端每次请求时必须向服务器发送
//must-revalidate:作用与no-cache相同,但更严谨
//no-store:缓存将不存在response,包括header和body。
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
// 本地无缓存,自动刷新页面
resp.setHeader("Pragma", "no-cache");
// Expires实体报头域给出响应过期的日期和时间,小于等于0表示当前页面立即过期,
// 为了让浏览器不要缓存页面,也可以利用Expires实体报关域,设置为0
resp.setDateHeader("Expires", 0);
/**********************************输出某文件*******************************/
//设置context-disposition响应头,控制浏览器以下载形式打开
//response.setHeader("content-disposition","attachment;filename="+URLEncoder.encode(fileName,"UTF-8"));
response.setHeader("Content-disposition", "attachment;filename=文件名称");
// 由于导出格式是excel的文件,设置导出文件的响应头部信息
response.setContentType("application/vnd.ms-excel");
/*
'doc' => 'application/msword',
'bin' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'so' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'dir' => 'application/x-director',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => 'application/zip',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mp3' => 'audio/mpeg',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'txt' => 'text/plain',
'xsl' => 'text/xml',
'xml' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
*/
/**********************************禁止图片缓存*******************************/
// 禁止图像缓存。
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
// 将图像输出到Servlet输出流中。
ServletOutputStream out = response.getOutputStream();
ImageIO.write(captchaEngine.generatorCaptcha(request), "jpeg", out);
/*************************************其他*************************************/
response.setStatus(302)//临时定向响应码
ponse.setHeader("Location","/day03_00_ResponseHeader/servlet/ResponseHeaderDemo2");///day03_00_ResponseHeader/servlet/ResponseHeaderDemo2 代表转向的地址
response.setHeader("Refresh", "3;url=http://www.baidu.com"); //告诉客户端 三秒后刷新