在这个页面里点超链就会直接生成word:
<html>
<head>
<title>word</title>
</head>
<body>
<p><a href="new.jsp">word</a></p>
</body>
</html>
生成word的代码:
<%@ page contentType="application/msword;charset=gb2312" %>
<%@ page import="*****%>
<%
response.setHeader("Content-disposition","inline; filename=test1.doc"); //线上浏览方式
response.setHeader("Content-disposition","attachment; filename=test1.doc");//下载方式
%>
<html>
......全是你需要的代码..你要显示的东东和一般的JSP页面的写法没有任何不同.....
</html>
<%
String filename = "东东--";
response.setHeader("Content-Disposition", "attachment; filename="+ java.net.URLEncoder.encode(filename, "UTF-8") +".doc");%>用utf-8可以实现中文名字的书写
本文介绍了一个使用JSP生成Word文档的示例,包括设置响应头以支持中文文件名、定义文档内容等步骤。该方法适用于需要在线浏览或下载Word文档的应用场景。

被折叠的 条评论
为什么被折叠?



