Chinaunix首页 | 论坛 | 博客
  • 博客访问: 925494
  • 博文数量: 264
  • 博客积分: 10107
  • 博客等级: 上将
  • 技术积分: 2455
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-09 16:34
文章分类

全部博文(264)

文章存档

2012年(1)

2011年(11)

2010年(128)

2009年(82)

2008年(42)

我的朋友

分类: Java

2010-10-11 13:55:26

 

关键字: pdf 动态 在线 jsp
这里使用的jsp
采用动态创建方式进行在线生成和下载
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'index.jsp' starting page
	
	
	    
	
	
	
  
  
  
    This is my JSP page. 
name :

没什么说得 一个表单提交页

呵呵 下面的是重点 文件生成页
<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<%@ page language="java" import="java.util.*"%>
<%@ page language="java" import="com.lowagie.text.*,com.lowagie.text.pdf.*"%>
<%@ page language="java" import="java.io.*"%>
<%
	response.reset();
	//创建文件头信息
	response.setContentType("application/x-msdownload");  
	response.setHeader("Content-Disposition",   "attachment;   filename="+new String(("hello"+request.getParameter("tname")+".pdf").getBytes(),"iso8859-1"));  
	//文件输出流
	ServletOutputStream sos = response.getOutputStream();  
	Document doc = new Document();
	PdfWriter.getInstance(doc, sos);  
	doc.open();  
	doc.add(new Paragraph("Hello "+request.getParameter("tname")+" !"));  
	doc.close();
	//关闭
	sos.flush();
	sos.close();
	out.clear();
	out = pageContext.pushBody();
 %>

  • (2.5 MB)
  • 下载次数: 7
阅读(425) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~