1 29 package net.sf.jasperreports.ebank; 30 31 import java.io.*; 32 import java.util.*; 33 import javax.servlet.*; 34 import javax.servlet.http.*; 35 36 37 41 public class PdfServlet extends HttpServlet 42 { 43 44 45 48 public void service( 49 HttpServletRequest request, 50 HttpServletResponse response 51 ) throws IOException, ServletException 52 { 53 byte[] bytes = null; 54 55 ReportBean reportBean = (ReportBean)request.getSession().getAttribute("reportBean"); 56 if (reportBean != null) 57 { 58 bytes = reportBean.getPdf(); 59 } 60 61 if (bytes != null && bytes.length > 0) 62 { 63 response.setContentType("application/pdf"); 64 response.setContentLength(bytes.length); 65 ServletOutputStream ouputStream = response.getOutputStream(); 66 67 try 68 { 69 ouputStream.write(bytes, 0, bytes.length); 70 ouputStream.flush(); 71 } 72 catch (IOException e) 73 { 74 if (ouputStream != null) 75 { 76 try 77 { 78 ouputStream.close(); 79 } 80 catch (IOException ex) 81 { 82 } 83 } 84 } 85 } 86 else 87 { 88 response.setContentType("text/html"); 89 PrintWriter out = response.getWriter(); 90 out.println("<html>"); 91 out.println("<body bgcolor=\"white\">"); 92 out.println("<span class=\"bold\">Empty response.</span>"); 93 out.println("</body>"); 94 out.println("</html>"); 95 } 96 } 97 98 99 } 100 | Popular Tags |