Excel导出中HttpServletResponse消息头参数设置

response.setCharacterEncoding("UTF-8");
//编码格式为UTF-8

response.setContentType("application/vnd.ms-excel; charset=UTF-8");
//让服务器告诉浏览器它发送的数据属于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("Content-Transfer-Encoding", "binary");
//描述内容在传输过程中的编码格式,BINARY可能不止包含非ASCII字符,还可能不是一个短行(超过1000字符)。

response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
//must-revalidate:强制页面不缓存,post-check=0, pre-check=0:0秒后,在显示给用户之前,该对象被选中进行更新过

response.setHeader("Pragma", "public");
//表示响应可能是任何缓存的,即使它只是通常是非缓存或可缓存的仅在非共享缓存中。

response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xls\"");
【Excel导出中HttpServletResponse消息头参数设置】//告诉浏览器这个文件的名字和类型,attachment:作为附件下载;inline:直接打开

    推荐阅读