yamanhashem Posted November 22, 2014 Posted November 22, 2014 I need to solve my problem, i am using jasper report 5.6 in seam 2.3 to generate chart but the result is html what should i do?****My Java Codeimport java.sql.Connection;import java.sql.SQLException;import java.sql.Timestamp;import java.util.Calendar;import java.util.Date;import java.util.HashMap;import java.util.Map;import javax.naming.InitialContext;import javax.sql.DataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRExporter;import net.sf.jasperreports.engine.JRExporterParameter;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;import net.sf.jasperreports.engine.export.HtmlExporter;import net.sf.jasperreports.engine.export.JRHtmlExporter;import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;import net.sf.jasperreports.export.HtmlExporterOutput;import net.sf.jasperreports.export.SimpleHtmlReportConfiguration;import org.jboss.seam.ScopeType;import org.jboss.seam.annotations.In;import org.jboss.seam.annotations.Name;import org.jboss.seam.annotations.Scope;import org.jboss.seam.contexts.Contexts;import com.twoMinuteOffer.action.SysUserHome;import com.twoMinuteOffer.model.SysUser;import com.twoMinuteOffer.report.file.LoadJrxmlFile;@Name("adminReport")public class AdminReport { private String reportString; private JasperPrint jasperPrint; String serverPath = System.getProperty("jboss.server.base.dir"); public String runAdminReport(){ Connection connection = null; try { InitialContext ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup("java:/TwoMinuteOfferDatasource"); connection = ds.getConnection(); Map<String, Object> parameters = new HashMap<String, Object>(); try { jasperPrint = JasperFillManager.fillReport(LoadJrxmlFile.getReport("adminReport.jasper"), parameters ,connection); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } setReportString(executeReportAsHtml(jasperPrint, null)); } catch (Exception e) { e.printStackTrace(); } finally{ try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } return getReportString(); } public String executeReportAsHtml(JasperPrint print, String sessionPrintAttributeName) throws Exception{ HtmlExporter exporter = null; if(sessionPrintAttributeName == null){ sessionPrintAttributeName = net.sf.jasperreports.j2ee.servlets.ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE; } StringBuffer sb = new StringBuffer(); Contexts.getSessionContext().set(sessionPrintAttributeName, print); exporter = new HtmlExporter(); exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER,sb); exporter.setParameter(JRExporterParameter.JASPER_PRINT,print); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); exporter.exportReport(); String imageURI = "image?time="+System.currentTimeMillis()+"&image="; if(sessionPrintAttributeName == null){ //use default sessionPrintAttributeName = net.sf.jasperreports.j2ee.servlets.ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE; imageURI = "image?time="+System.currentTimeMillis()+"&image="; } else { imageURI = "image?time="+System.currentTimeMillis()+"&jrprint="+sessionPrintAttributeName+"&image="; } exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, imageURI); return sb.toString(); } public void setReportString(String reportString) { this.reportString = reportString; } public String getReportString() { return reportString; } }*****My HTML code<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.org/schema/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml"> <ui:define name="body"> <h:form> <s:div> #{adminReport.runAdminReport()} </s:div> </h:form> </ui:define></ui:composition> please help me...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now