博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java Servlet 下载 itext 生成的2003 word 文档(java生成word文档3)
阅读量:7093 次
发布时间:2019-06-28

本文共 1616 字,大约阅读时间需要 5 分钟。

hot3.png

package cn.net.seek.servlet.legalidea;import java.io.BufferedOutputStream;import java.io.IOException;import java.io.OutputStream;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.PageSize;import com.lowagie.text.rtf.RtfWriter2;import cn.net.seek.service.LegalDraftService;public class ExportAllIdeaServlet extends HttpServlet {	private static final long serialVersionUID = -6937472436989564187L;	public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		doPost(request, response);	}	public void doPost(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		String puid = request.getParameter("puid");		LegalDraftService service=new LegalDraftService();		String title = service.findTitleByPuid(puid);		OutputStream toClient=new BufferedOutputStream(response.getOutputStream());		response.addHeader("Content-Disposition", "attachment;filename="				+ new String(title.getBytes("gbk"), "iso8859-1") + ".doc");		response.setContentType("application/vnd.ms-word");		Document document = new Document(PageSize.A4);		RtfWriter2.getInstance(document, toClient);		document.open();		try {			service.downAllIdeaByPuid(puid, title, document);		} catch (DocumentException e) {			e.printStackTrace();		}		document.close();		toClient.flush();		toClient.close();	}}

转载于:https://my.oschina.net/u/555639/blog/226953

你可能感兴趣的文章
Spring AOP实现对redis统一管理 (注解方式)
查看>>
【MVVM】- Avalon 数组操作
查看>>
【VMCloud云平台】SCSM(八)SCSM创建请求产品
查看>>
我的友情链接
查看>>
虚拟机的时间同步
查看>>
在XenServer 6.0中设置自动启动虚拟机
查看>>
【大数据培训】大数据带你寻找“惊心动魄”
查看>>
centos7修改网卡一致性命名
查看>>
文件管理命令及变量基础
查看>>
find
查看>>
如何理解磁力
查看>>
安卓学习-NDK开发
查看>>
Linux的基础学习
查看>>
MyBatis--01.基础
查看>>
JEESZ-Redis分布式缓存安装和使用
查看>>
for和each的区别
查看>>
为什么我这样做会出错,求教
查看>>
【Java多线程】的学习总结
查看>>
五分钟搭建你的第一个区块链应用
查看>>
家庭WiFi有限的访问权限
查看>>