First intersection 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");PD f.make (request,response,id); return null;}}
The Output method
/* * 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_fi Le2=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 (); I Nputstream 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 (); } }
JAVA Read PDF file