Jump to content
Changes to the Jaspersoft community edition download ×

subreport in Tomcat


2004 IR Help

Recommended Posts

By: hj1122 - hj1122

subreport in Tomcat

2004-10-26 02:56

Can anyone give me a sample of how to deploy a master report with several subreports in Tomcat webapps?

 

My codes are :

 

File rd = new File(application.getRealPath("")+"/reports/jreport_r03_1.jrxml");

File rds = new File(application.getRealPath("")+"/reports/jSubreport_r03_4.jrxml");

JasperReport report = JasperCompileManager.compileReport( rd.getPath() );

JasperReport subreport = JasperCompileManager.compileReport( rds.getPath() );

 

Map hm = new HashMap();

hm.put("jSubreport_r03_4", subreport);

hm.put("jreport_r03_1", report);

JasperPrint jpr = JasperFillManager.fillReport(jr, hm, conn);

 

But it still doesn't work? Please can anyone give me some hints?

 

 

 

 

 

By: hj1122 - hj1122

the error message is

2004-10-26 03:06

type Exception report

 

message

 

description The server encountered an internal error () that prevented it from fulfilling this request.

 

exception

 

javax.servlet.ServletException: Errors were encountered when compiling report expressions class file:

See error messages above.

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)

org.apache.jsp.viewApp3_005fr03_005f1_jsp._jspService(viewApp3_005fr03_005f1_jsp.java:387)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 

 

root cause

 

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:

See error messages above.

net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.compileReport(JRAbstractJavaCompiler.java:155)

net.sf.jasperreports.engine.design.JRDefaultCompiler.compileReport(JRDefaultCompiler.java:137)

net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:199)

net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:151)

org.apache.jsp.viewApp3_005fr03_005f1_jsp._jspService(viewApp3_005fr03_005f1_jsp.java:165)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 

 

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.

 

 

 

 

 

 

By: hj1122 - hj1122

RE: subreport in Tomcat

2004-10-26 04:01

1. I can't even load the jasper file from the location, that's why I had to choose to use load jrxml, and it works for single report. Do I need to set up something in order to load .jasper before I execute :

 

JasperReport report = (JasperReport) JRLoader.loadObjectFromLocation("C:/Tomcat5/webapps/arp/WEB-INF/classes/dbtest/jreport_r02_3.jasper"); ?

 

 

2. To make things clear, I attached my jSubreport.jrxml, is this the one that should be specified?

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="jSubreport_r02_3"

columnCount="1"

printOrder="Vertical"

orientation="Landscape"

pageWidth="129"

pageHeight="23"

columnWidth="129"

columnSpacing="0"

leftMargin="0"

rightMargin="0"

topMargin="0"

bottomMargin="0"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="2" />

<parameter name="greek" isForPrompting="true" class="java.lang.String"/>

<parameter name="PATH" isForPrompting="false" class="java.lang.String">

<defaultValueExpression ><![CDATA["C:\Tomcat5\webapps\arp\Web-inf\classes\"]]></defaultValueExpression>

</parameter>

<queryString><![CDATA[exec mr_get_und @id_typ_node1=DESK', @id_group=1, @id_typ_sort='am_delta', @id_pointwise=1, @id_cl_asset_und='ALL', @id_point_vega=0, @id_own_bus=3, @id_node1=10000006, @id_single_param = 1 , @id_param_rsk= 'DELT]]></queryString>

<field name="nm_imnt" class="java.lang.String"/>

<field name="nm_upper_node" class="java.lang.String"/>

<field name="id_typ_imnt" class="java.lang.String"/>

<field name="id_param_rsk" class="java.lang.String"/>

<field name="am_exp_rsk" class="java.lang.Double"/>

<field name="region_dt_bus" class="java.lang.String"/>

<variable name="test" class="java.lang.String" resetType="None" calculation="Nothing">

<variableExpression><![CDATA["test"]]></variableExpression>

<initialValueExpression><![CDATA["test"]]></initialValueExpression>

</variable>

<background>

<band height="1" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="0" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="0" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="0" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="16" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="0"

y="0"

width="80"

height="16"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false">

<printWhenExpression><![CDATA[$F{id_param_rsk}.equals("DELT") ? Boolean.TRUE : Boolean.FALSE]]></printWhenExpression>

</reportElement>

<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{nm_imnt}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="#,##0;(#,##0)" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Transparent"

x="81"

y="0"

width="46"

height="16"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false">

<printWhenExpression><![CDATA[$F{id_param_rsk}.equals("DELT") ? Boolean.TRUE : Boolean.FALSE]]></printWhenExpression>

</reportElement>

<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.Double"><![CDATA[new Double($F{am_exp_rsk}.doubleValue()/1000.00)]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="#,##0;(#,##0)" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="81"

y="0"

width="46"

height="16"

forecolor="#FF3333"

backcolor="#FFFFFF"

key="textField-2"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false">

<printWhenExpression><![CDATA[$F{id_param_rsk}.equals("DELT") ? Boolean.TRUE : Boolean.FALSE]]></printWhenExpression>

</reportElement>

<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.Double"><![CDATA[new Double($F{am_exp_rsk}.doubleValue()/1000.00)]]></textFieldExpression>

</textField>

<line direction="TopDown">

<reportElement

mode="Opaque"

x="128"

y="0"

width="1"

height="16"

forecolor="#000000"

backcolor="#FFFFFF"

key="line-2"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false">

<printWhenExpression><![CDATA[$F{id_param_rsk}.equals("DELT") ? Boolean.TRUE : Boolean.FALSE]]></printWhenExpression>

</reportElement>

<graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" />

</line>

</band>

</detail>

<columnFooter>

<band height="0" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="0" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="0" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

 

Thanks & Regards

 

jia

 

 

 

 

By: hj1122 - hj1122

this is the error message for jasper loading

2004-10-26 04:04

type Exception report

 

message

 

description The server encountered an internal error () that prevented it from fulfilling this request.

 

exception

 

javax.servlet.ServletException: Class not found when loading object from file : C:Tomcat5webappsarpWEB-INFclassesjSubreport_r02_3.jasper

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)

org.apache.jsp.viewApp3_005fr02_jsp._jspService(viewApp3_005fr02_jsp.java:397)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 

 

root cause

 

net.sf.jasperreports.engine.JRException: Class not found when loading object from file : C:Tomcat5webappsarpWEB-INFclassesjSubreport_r02_3.jasper

net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:137)

net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:279)

org.apache.jsp.viewApp3_005fr02_jsp._jspService(viewApp3_005fr02_jsp.java:170)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 

 

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.

 

 

 

 

 

 

By: hj1122 - hj1122

RE: subreport in Tomcat

2004-10-26 04:08

I tried to put jasper files under either the folder "C:Tomcat5webappsarpWEB-INFclasses" or "C:Tomcat5webappsarpWEB-INFclassesdbtest", neither works.

 

 

 

 

By: Giulio Toffoli - gt78

RE: subreport in Tomcat

2004-10-26 03:11

 

First of all, use compiled jasper files in tomcat (if you don't generate the xml on the fly, compile every time has not sense).

 

A way is put the path of the subreport in a parameter, so jasperreports can retrive it yourself.

 

The subreport expression will be something like this:

 

$P{PathToSubreport_r03_4}

 

Then in your servlet...

 

map.put("PathToSubreport1", application.getRealPath("")+"/reports/jSubreport_r03_4.jasper");

 

Giulio

 

 

 

 

By: hj1122 - hj1122

RE: subreport in Tomcat

2004-10-27 07:03

problem solved. Thanks for your help, Giulio!

 

I attached the corresponding codes, I hope it would help people with the similar question:

 

 

File rd = new File(application.getRealPath("")+"/reports/jreport_r02_3.jasper");

HashMap hm = new HashMap();

hm.put("BaseDir", rd.getParentFile());

JasperPrint jpr = JasperFillManager.fillReport(jr, hm, conn);

 

For compilation and filling details, just refer to the webapps samples in the jasperreport.

 

 

 

 

By: hj1122 - hj1122

RE: subreport in Tomcat

2004-10-27 09:25

I'm just wondering is it possible to fill the subreport by using JRDataSource instead of connection. And in JSP, how can we implement this by filling master report and subreport? Is it possible to add subreport as a parameter in master report's map? Something like :

 

JasperCompileManager.compileReportToFile(application.getRealPath("/reports/jSubreport_r02_3.jrxml"));

JasperCompileManager.compileReportToFile(application.getRealPath("/reports/jreport_r02_3.jrxml"));

File rds = new File(application.getRealPath("")+"/reports/jSubreport_r02_3.jasper");

JasperReport jrsub = (JasperReport)JRLoader.loadObject(rds.getPath());

File rd = new File(application.getRealPath("")+"/reports/jreport_r02_3.jasper");

JasperReport jr = (JasperReport)JRLoader.loadObject(rd.getPath());

 

HashMap hm = new HashMap();

hm.put("BaseDir", rd.getParentFile());

JasperPrint jprsub = JasperFillManager.fillReport(jrsub, hm, jrds);

 

HashMap hm2 = new HashMap();

hm2.put("BaseDir", rd.getParentFile());

hm2.put("jrsub", jrsub);

JasperPrint jpr = JasperFillManager.fillReport(jr, hm2, jrds);

 

Can anyone please give me some advice?

 

 

 

 

 

 

By: hj1122 - hj1122

RE: subreport in Tomcat

2004-10-28 04:14

Are there any default attributes for the parameters of jasperreport. For example, in JasperFillManager.fillReport(JasperReport jasperReport, java.util.Map parameters, JRDataSource jrDataSource)

 

Can we set any parameters as we want? How would FillManager recognize the meaning of my parameter?

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...