Installed JRE & JDK 1.4.2_08 on server and a Windows PC.
Unzipped iReports-0.5.0 to the hard drive.
Copied tools.jar from the JRE to iReports-0.5.0/lib
Set up Tomcat 4.1.29 as usual on the server. Edited Catalina.conf to use the right JDK by setting JAVA_HOME then exporting it. Also added -Djava.awt.headless=true to JAVA_OPTS.
I created an application called reports
Went to webapps/reports/WEB-INF/lib
Copied the following files from iReports/lib
bsh-1.3.0.jar
commons-collections.jar
commons-logging-api.jar
itext-1.02b.jar
commons-beanutils.jar
commons-digester.jar
commons-logging.jar
jasperreports-0.6.7.jartools.jar
Looking at an old install, I also copied oracle.jar. Not sure where this came from but I assume it was needed to access our Oracle DB.
So now I create an index.html in /reports that has a link to /jsp/myreport.jsp
reports/jsp/myreport.jsp looks like this:
<%@page import="javax.sql.DataSource" %>
<%@page import="java.sql.Connection" %>
<%@page import="java.sql.CallableStatement" %>
<%@page import="java.sql.Statement" %>
<%@page import="java.sql.ResultSet" %>
<%@page import="java.util.Date" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.lang.Integer" %>
<%@ page errorPage="error.jsp" %>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.util.*" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<% InitialContext context = new InitialContext(); DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/test/testDB"); Connection connection = dataSource.getConnection(); File reportFile = new File(application.getRealPath("/reports/JasperTest.jasper")); JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); Map parameters = new HashMap(); parameters.put("ReportTitle", "Address Report"); parameters.put("BaseDir", reportFile.getParentFile()); Integer userpatientid = new Integer(25394); parameters.put("PatientId", userpatientid); JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, connection ); JRHtmlExporter exporter = new JRHtmlExporter(); StringBuffer sbuffer = new StringBuffer(); Map imagesMap = new HashMap(); session.setAttribute("IMAGES_MAP", imagesMap);
// for PDF output, use exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
// I know I know it says XLS, but it works! Otherwise there is whitespace between rows
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image.jsp?image="); exporter.exportReport(); %>
Restart Tomcat and it works!
Subscribe to:
Post Comments (Atom)
Labels
- Java (34)
- Oracle (27)
- javascript (24)
- NIX administration (19)
- Reporting (18)
- XML (17)
- Web Graphics (10)
- perl (10)
- CSS (9)
- Tomcat (8)
- Android (7)
- Matlab (7)
- XSL (7)
- HTML (6)
- SQL (6)
- XForms (6)
- browser quirks (6)
- Orbeon XForms (5)
- Solaris (5)
- AJAX (4)
- Mirth Project (4)
- PHP (4)
- Video (4)
- Arduino (3)
- Eclipse (3)
- JPA (3)
- JSP (3)
- JSTL (3)
- LAMPS (3)
- SSH (3)
- SVN (3)
- Hibernate (2)
- Netbeans (2)
- Networking (2)
- Python (2)
- Windows (2)
- Wordpress (2)
- XHTML (2)
- Alfresco (1)
- Architecture (1)
- ArduPilot (1)
- Arduino Yun (1)
- Arduplane (1)
- Audio Recording (1)
- Betaflight (1)
- CouchDB (1)
- DIY (1)
- Design (1)
- FPV (1)
- JSON (1)
- JUnit (1)
- Mobile Development (1)
- Printing (1)
- RC Airplane (1)
- REST (1)
- Scalability (1)
- Struts (1)
- Tools (1)
- Virtualization (1)
- Web services (1)
- camera (1)
- canon (1)
- gphoto2 (1)
- jQuery (1)
- ubuntu (1)
- unix (1)
No comments:
Post a Comment