分类: Java
2010-10-11 13:55:26
<%@ 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.
<%@ 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(); %>