日期:2014-05-17 浏览次数:20666 次
在tomcat下面找到要转换的格式:
<mime-mapping> <extension>doc</extension> <mime-type>application/msword</mime-type> </mime-mapping> <mime-mapping> <extension>xls</extension> <mime-type>application/vnd.ms-excel</mime-type> </mime-mapping> <mime-mapping> <extension>txt</extension> <mime-type>text/plain</mime-type> </mime-mapping>
JSP
<%@ page contentType="text/html; charset=GBK" %> <% String WriteType="application/vnd.ms-excel;charset=GBK"; response.setContentType(WriteType); %> <HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK">。。。。。。
?
这样即可。
如果想设置打开页面时出现下载页面和下载文件时的名字设置
response.setHeader("Content-disposition","attachment; filename="+fileName);//inline
attachment为下载,inline为直接打开,filename即为文件名字,带后缀。