1、简单设置
导出为excel:
<%
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename=test.xls");
%>
导出为word:
<%
response.setContentType("application/msword;charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename=test.doc");
%>
test.jsp:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<%
response.setContentType("application/msword;charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename=test.doc"); //用word打开页面
%>
<html>
<body>
<table>
<tr>
<td>8888</td>
</tr>
</table>
</body>
</html>
用这种方法导出,有时候html里面的文字会变成乱码
2、这种方法导出的时候没有乱码
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
Result rs_data=null;
String t_flmc = request.getParameter("t_flmc");
String t_bcnr = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"></head><body>"+request.getParameter("t_bcnr");
t_bcnr += "</body></html>";
//t_bcnr = java.net.URLDecoder.decode(t_bcnr,"GB2312");
out.clear();
response.setHeader("Content-Disposition","attachment;filename=dcsj.xls");
response.setContentType("application/vnd.ms-excel;charset=gb2312");
out.print(t_bcnr);