日期:2014-05-16  浏览次数:20328 次

jsp页面导出成word文件
<%@ page contentType="application/vnd.ms-word; charset=utf-8"%>
<%@ page pageEncoding="utf-8"%>
<%@ page import="java.net.URLEncoder" %>

<%
	String fileName = "文件名.doc";
         //对中文文件名编码
	fileName = URLEncoder.encode("文件名", "UTF-8") + ".doc";
	response.setHeader("Content-disposition", "attachment; filename=" + fileName);
%>

<html xmlns:v="urn:schemas-microsoft-com:vml" 
      xmlns:o="urn:schemas-microsoft-com:office:office" 
      xmlns:w="urn:schemas-microsoft-com:office:word" 
      xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" 
      xmlns:st1="urn:schemas-microsoft-com:office:smarttags" 
      xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 12">
<meta name="Originator" content="Microsoft Word 12"> 
<title>JSP页面导出为Word文档</title>
</head>
<body>
。。。页面内容。。。
</body>
</html>

这种方式是可以导出,这是种简单的方式,但是文件名会出现乱码问题

fileName = new String(fileName.getBytes("GBK"), "ISO8859_1")+ ".doc";

就没事了。。。。。