第一个路口action
/* * wuhan syspro author zhangrui 2010/08/23 */ package jp.co.syspro.poo.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class PrintPdfAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PdfExport pdf = new PdfExport(); String id=request.getParameter("id"); pdf.make(request,response,id); return null; } }
进行输出方法
/* * author syspro wuhan zhangrui 2010/8/20 */ package jp.co.syspro.poo.action; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.lowagie.text.pdf.PdfPageEventHelper; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfTemplate; import jp.co.syspro.poo.dao.System3Dao; public class PdfExport extends PdfPageEventHelper { public PdfTemplate tpl; public BaseFont bf; public void make(HttpServletRequest request, HttpServletResponse response,String id) throws Exception{ ArrayList f_file2=System3Dao.getInstance().getFile(id); InputStream f_file=(InputStream)f_file2.get(0); Integer f_size=Integer.parseInt(f_file2.get(1).toString()); response.reset(); response.setContentType("application/pdf"); OutputStream output = response.getOutputStream(); InputStream fis = f_file; byte[] b = new byte[f_size]; int i = 0; while ((i = fis.read(b)) > 0) { output.write(b, 0, i); } output.flush(); } }
时间: 2024-10-13 03:57:49