KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > ebank > ImageServlet


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2005 Teodor Danciu teodord@users.sourceforge.net
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * Teodor Danciu
24  * 173, Calea Calarasilor, Bl. 42, Sc. 1, Ap. 18
25  * Postal code 030615, Sector 3
26  * Bucharest, ROMANIA
27  * Email: teodord@users.sourceforge.net
28  */

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 /**
38  * @author Teodor Danciu (teodord@users.sourceforge.net)
39  * @version $Id: ImageServlet.java,v 1.4 2005/02/03 15:31:47 teodord Exp $
40  */

41 public class ImageServlet extends HttpServlet
42 {
43
44
45     /**
46      *
47      */

48     public void service(
49         HttpServletRequest request,
50         HttpServletResponse response
51         ) throws IOException, ServletException
52     {
53         Map imagesMap = ((ReportBean)request.getSession().getAttribute("reportBean")).getImagesMap();
54     
55         if (imagesMap != null)
56         {
57             String JavaDoc imageName = request.getParameter("image");
58             if (imageName != null)
59             {
60                 byte[] imageData = (byte[])imagesMap.get(imageName);
61     
62                 response.setContentLength(imageData.length);
63                 ServletOutputStream ouputStream = response.getOutputStream();
64                 ouputStream.write(imageData, 0, imageData.length);
65                 ouputStream.flush();
66                 ouputStream.close();
67             }
68         }
69     }
70
71
72 }
73
Popular Tags