KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servlets > CompileServlet


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
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  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package servlets;
29
30 import java.io.IOException JavaDoc;
31 import java.io.PrintWriter JavaDoc;
32
33 import javax.servlet.ServletContext JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.http.HttpServlet JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38
39 import net.sf.jasperreports.engine.JRException;
40 import net.sf.jasperreports.engine.JasperCompileManager;
41
42
43 /**
44  * @author Teodor Danciu (teodord@users.sourceforge.net)
45  * @version $Id: CompileServlet.java 1236 2006-04-22 10:51:44 +0300 (Sat, 22 Apr 2006) teodord $
46  */

47 public class CompileServlet extends HttpServlet JavaDoc
48 {
49
50
51     /**
52      *
53      */

54     public void service(
55         HttpServletRequest JavaDoc request,
56         HttpServletResponse JavaDoc response
57         ) throws IOException JavaDoc, ServletException JavaDoc
58     {
59         ServletContext JavaDoc context = this.getServletConfig().getServletContext();
60
61         response.setContentType("text/html");
62         PrintWriter JavaDoc out = response.getWriter();
63
64         try
65         {
66             JasperCompileManager.compileReportToFile(context.getRealPath("/reports/WebappReport.jrxml"));
67         }
68         catch (JRException e)
69         {
70             out.println("<html>");
71             out.println("<head>");
72             out.println("<title>JasperReports - Web Application Sample</title>");
73             out.println("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"../stylesheet.css\" title=\"Style\">");
74             out.println("</head>");
75             
76             out.println("<body bgcolor=\"white\">");
77
78             out.println("<span class=\"bnew\">JasperReports encountered this error :</span>");
79             out.println("<pre>");
80
81             e.printStackTrace(out);
82
83             out.println("</pre>");
84
85             out.println("</body>");
86             out.println("</html>");
87
88             return;
89         }
90
91         out.println("<html>");
92         out.println("<head>");
93         out.println("<title>JasperReports - Web Application Sample</title>");
94         out.println("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"../stylesheet.css\" title=\"Style\">");
95         out.println("</head>");
96         
97         out.println("<body bgcolor=\"white\">");
98
99         out.println("<span class=\"bold\">The JRXML report design was successfully compiled.</span>");
100
101         out.println("</body>");
102         out.println("</html>");
103     }
104
105
106 }
107
Popular Tags