Http://go.rritw.com/www.360doc.com/content/10/1109/19/3715754_68004729.shtml
Birt is a eclipse-based open source code report system. It is primarily used in Web applications based on Java and EE. Birt is mainly composed of two parts: one is based on Eclipse's presentation design and one can be added to your service of the departure component. Birt also provides a chart making engine.
Birt home:http://go.rritw.com/www.eclipse.org/birt/phoenix/ Birt Environment and download: [Url]http://download.eclipse.org/birt/downloads [/URL] Birt Tutorial: http://go.rritw.com/www.eclipse.org/birt/phoenix/tutorial/ Eclipse theory Altar: [url]http://www.eclipseworld.org/bbs/[/URL] Birt Example Demo: [url]http://go.rritw.com/www.eclipse.org/birt/phoenix/examples/[/URL] [url]http://download3.eclipse.org/birt/downloads/examples/misc/birt/birt_demo_camv3.html [/URL] [url]http://download3.eclipse.org/birt/downloads/demos/myfirstreport.html [/URL]
Birt using a small knot ide:birt-report-designer-all-in-one-2.1.2 (the first person to download, download is a ECLIPSE,BIRT has been installed, convenient) runtime:birt-runtime-2.1.2 Jdk:jdk1.5.0_02
And there are two ways to do it now. One: Direct use of webviewerexample in birt_runtime_2.1.2. 1. It was released to C:\jakarta-tomcat-5.0.28\webapps, and renamed it Birtapp. 2. Create a new folder Lib under Birtapp \web-inf\platform\plugins\com.lowagie.itext and copy the Itext-1.3.jar and Itextasian.jar into it. 3. The completed report, such as Test.rptdesign, is placed in the root of Birtapp and can be passed through Http://localhost:8080/birt/frameset?__report=test.rptdesign (opposite Path) Or Http://localhost:8080/birt/frameset?__report=C:/jakarta-tomcat-5.0.28/webapps/birt/test.rptdesign (absolute path) To visit. If the report is set to a parameter, simply stitch the parameters and values after the above URL. Eg:http://localhost:8080/birt/frameset?__report=test.rptdesign&sample=my+parameter Second: Use the report Engine API provided by Birt in our program to adjust the table and display the report. 1. Create a new Web item webrpt. 2. Create a new folder lib in the Web-inf catalog under the WEBRPT Web module and copy all the files under Birt-runtime-2_1_2\reportengine\lib into it. 3. As above, also in the Web-inf of the new folder platform, and Birt-runtime-2_1_2\reportengine under the plugins and the configuration into it. 4. Copy the Itext-1.3.jar and Itextasian.jar into the Lib catalogue of the Platform\plugins\com.lowagie.itext folder (if this is not the case, create a new one), or copy the jar package into the Web-inf \lib is also available under the catalogue. 5. Create a new images and Reports folder under the root of the WEBRPT Web template. Where the reports folder is placed in the folder Completed report file. 6. Of course, the use of the library is also placed in the Lib file folder. 7. Use the report Engine API to develop and display a related program. The codes are as follows: Webreport.java
Package Com.lisa;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import Java.util.HashMap;
Import Java.util.logging.Level;
Import Java.util.logging.Logger;
Import Javax.servlet.ServletContext;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import org.eclipse.birt.report.engine.api.EngineConstants;
Import Org.eclipse.birt.report.engine.api.HTMLRenderContext;
Import org.eclipse.birt.report.engine.api.HTMLRenderOption;
Import org.eclipse.birt.report.engine.api.IReportRunnable;
Import Org.eclipse.birt.report.engine.api.IRunAndRenderTask;
Import Org.eclipse.birt.report.engine.api.IReportEngine;
public class Webreport extends HttpServlet {/** * */private static final long serialversionuid = 1L;
/** * Constructor of the object.
*/private Ireportengine birtreportengine = null; protected static Logger Logger = Logger.getlogger ("Org.eclipse.birt ");
Public Webreport () {super ();
}/** * Destruction of the servlet.
*/public void Destroy () {Super.destroy ();
Birtengine.destroybirtengine ();
}/** * The Doget method of the servlet.
* */public void doget (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {
System.out.println ("Doget .........");
Get report name and launch the engine//resp.setcontenttype ("text/html");
Resp.setcontenttype ("Application/pdf");
Resp.setheader ("content-disposition", "inline; filename=test.pdf");
String ReportName = Req.getparameter ("ReportName");
System.out.println ("ReportName:::" +reportname);
ServletContext sc = req.getsession (). Getservletcontext ();
This.birtreportengine = Birtengine.getbirtengine (SC);
Setup image directory Htmlrendercontext Rendercontext = new Htmlrendercontext ();
Rendercontext.setbaseimageurl (Req.getcontextpath () + "/images"); Rendercontext.setimagedirectory (Sc.getrealpath ("/imagEs "));
Logger.log (Level.fine, "image directory" + sc.getrealpath ("/images"));
SYSTEM.OUT.PRINTLN ("stdout image directory" + sc.getrealpath ("/images"));
HashMap Contextmap = new HashMap ();
Contextmap.put (Engineconstants.appcontext_html_render_context, Rendercontext);
Ireportrunnable design;
try {//open report Design design = Birtreportengine.openreportdesign (Sc.getrealpath ("/reports") + "/" +reportname);
Create task to run and render report Irunandrendertask task = Birtreportengine.createrunandrendertask (design);
Task.setappcontext (CONTEXTMAP);
HashMap parammap=new HashMap ();
Parammap.put ("param", "%");
Parammap.put ("Sample", "Lisa OK");
Task.setparametervalues (PARAMMAP);
Set output options htmlrenderoption options = new Htmlrenderoption ();
Options.setoutputformat (htmlrenderoption.output_format_html);
Options.setoutputformat (htmlrenderoption.output_format_pdf);
Options.setoutputstream (Resp.getoutputstream ());Task.setrenderoption (options);
Run report Task.run ();
Task.close ();
}catch (Exception e) {e.printstacktrace ();
throw new Servletexception (e);
}}/** * The DoPost method of the servlet. * */public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexceptio
n {response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter (); Out.println ("<!
DOCTYPE HTML public \ "-//W3C//DTD HTML 4.01 transitional//en\" > ");
Out.println ("<HTML>");
Out.println ("
Birtengine.java
Package Com.lisa;
Import Java.io.InputStream;
Import java.io.IOException;
Import java.util.Properties;
Import Java.util.logging.Level;
Import Org.eclipse.birt.report.engine.api.EngineConfig;
Import Org.eclipse.birt.report.engine.api.IReportEngine;
Import javax.servlet.*;
Import Org.eclipse.birt.core.framework.PlatformServletContext;
Import Org.eclipse.birt.core.framework.IPlatformContext;
Import Org.eclipse.birt.core.framework.Platform;
Import org.eclipse.birt.core.exception.BirtException;
Import Org.eclipse.birt.report.engine.api.IReportEngineFactory;
public class Birtengine {private static ireportengine birtengine = null;
private static Properties Configprops = new properties ();
Private final static String ConfigFile = "Com/lisa/birtconfig.properties";
public static synchronized void Initbirtconfig () {loadengineprops (); } public static synchronized Ireportengine getbirtengine (ServletContext SC) {if (birtengine = = null) {ENGINECONFI G config = newEngineconfig ();
if (configprops! = null) {String logLevel = Configprops.getproperty ("LogLevel");
Level level = Level.off;
if ("SEVERE". Equalsignorecase (LogLevel)) {level = Level.severe;
} else if ("WARNING". Equalsignorecase (LogLevel)) {level = level.warning;
} else if ("INFO". Equalsignorecase (LogLevel)) {level = Level.info;
} else if ("CONFIG". Equalsignorecase (LogLevel)) {level = Level.config;
} else if ("FINE". Equalsignorecase (LogLevel)) {level = Level.fine;
} else if ("finer". Equalsignorecase (LogLevel)) {level = Level.finer;
} else if ("FINEST". Equalsignorecase (LogLevel)) {level = Level.finest;
} else if ("OFF". Equalsignorecase (LogLevel)) {level = Level.off;
} config.setlogconfig (Configprops.getproperty ("Logdirectory"), level);
} config.setenginehome ("");
Iplatformcontext context = new Platformservletcontext (SC); Config.setplatformcontext ( context);
try {platform.startup (config);
} catch (Birtexception e) {e.printstacktrace (); } ireportenginefactory factory = (ireportenginefactory) Platform. Createfactoryobject (Ireportenginefactory.extensi
On_report_engine_factory);
Birtengine = factory.createreportengine (config);
} return birtengine;
public static synchronized void Destroybirtengine () {if (birtengine = = null) {return;
} birtengine.shutdown ();
Platform.shutdown ();
Birtengine = null;
} public Object Clone () throws Clonenotsupportedexception {throw new clonenotsupportedexception ();
} private static void Loadengineprops () {System.out.println ("Loadengineprops ..... .......)");
try {//config File must is in classpath ClassLoader cl = Thread.CurrentThread (). Getcontextclassloader ();
InputStream in = null;
in = Cl.getresourceasstream (configfile);
Configprops.load (in);
In.close (); } catch (IOException e) {E.printStackTrace (); }
}
}
Birtconfig.properties
Logdirectory=c:/temp
8. Through Web pages, you enter the name of the report that you want to visit and submit it to the related servlet that you request. test.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
9. Modify the Web. xml file as follows
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.4"
xmlns= "http://java.sun.com/xml/ns/ Java ee "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xsi:schemalocation=" http://java.sun.com/ XML/NS/J2EE
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name >WebReport</servlet-name>
<servlet-class>com.lisa.WebReport</servlet-class>
</ servlet>
<servlet-mapping>
<servlet-name>WebReport</servlet-name>
< Url-pattern>/webreport</url-pattern>
</servlet-mapping>
See Servlet Example.
Another: Some of the very practical tips learned in altar, thank you for the authors:) Sub-page (vii779): 2.1 After that, you can only follow the sub-group page, you want to press the fixed number of pages per page is difficult. In altar, we have introduced the way of passing the group, adding a page field to the page function. But the way the operation is slightly more complicated tedious. Through script, you can actually simplify the page. First, add a table, select the lines in the table, and switch to the script. Add the following codes to the OnRender event
RowNum = number (This.getrowdata (). Getexpressionvalue (' row["0"] ')) +1;
if (rowNum% ==0) {
this.getstyle (). pagebreakafter= "Always";
} else{
This.getstyle (). Pagebreakafter=null;
This is the fact that you can press the 20-page feature of each article. It is important to note that in run mode, you cannot see the page effect, and you will be able to see the page when you print the preview. In Framest (ctrl+shift+b) mode, you can see the full page effect.
Cardboard (PADDYCQ): Home---> Constant setting direction, type
PDF Chinese Password (mmwy): Put the Itext-1.3.jar, Itextasian.jar two jar bag in \plugins\com.lowagie.itext\lib, everything OK, since there is no Chinese problem. This is true even if you deploy to Linux.
URL code problem. mht Two workarounds: I. Java.net.URLDecoder.decode (Java.net.URLEncoder.encode ("Chinese")); Two If you use Tomcat to make a Web application server, modify the Server.xml file to add a uriencoding to the connector element. Eg:<connector port= "8080" maxthreads= "all minsparethreads=" "maxsparethreads=" "enablelookups="
false "Redirectport=" 8443 "acceptcount=" "
debug=" 0 "connectiontimeout=" 20000 "
disableuploadtimeout=" true "
Premise: 1. Use the runtime Viewer provided by Eclipse. 2. Use the Hyperlink method to view the report. 3. Use Tomcat.
Solutions by: Modify Tomcat's Server.xml file to add a usebodyencodingforuri= "true" to the connector element And, the Chinese parameter in the URL must be encoded in advance. eg String Param=java.net.urlencoder.encode ("Common Information table", "UTF-8"); <a href= ". /birt/frameset?__report=privilegerpt.rptdesign¶m=<%=param%> "> View </a> That is OK. From:iteye
|