Jump to content
Changes to the Jaspersoft community edition download ×

webapp : image generation in HTML rendering


Recommended Posts

By: bulkao - bulkao

webapp : image generation in HTML rendering

2006-04-25 02:36

Hi everyone,

 

This thread has already been posted, but no response was given...

So i give more infos about my config.

 

I desperatly try to display a report in HTML format from a servlet...

 

==> It works perfectly in PDF format (with the JasperExportManager.exportReportToPdf() method)

 

 

My webapp is deployed on JONAS server, in a war file, not in a explode form.

But Jonas creates automatically an exploded tree, from the war file.

 

 

##################

## in my servlet :

##################

PrintWriter out = res.getWriter();

res.setContentType("text/html");

JRHtmlExporter exporter = new JRHtmlExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "images/");

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(false));

try {

exporter.exportReport();

} catch (JRException jrex) {

...

}

 

##########################################################

## in my JRXML file, the image is renferenced like this :

##########################################################

 

<jasperReport

name="CnxPerDayChartScriptlet"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

columnWidth="515"

columnSpacing="0"

leftMargin="40"

rightMargin="40"

topMargin="50"

bottomMargin="50"

scriptletClass="com.axiliance.realsentry.wssologs.charts.CnxPerDayChartScriptlet"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

 

[...]

 

<!--

* PARAMETERS :

* - a Dataset object

* - a ChartConfig object : report characteristics

-->

<parameter name="dataset" isForPrompting="true" class="org.jfree.data.category.CategoryDataset"/>

<parameter name="chartDimension" isForPrompting="true" class="com.mycompany.charts.ChartDimension"/>

 

[...]

 

<image scaleImage="Clip" vAlign="Top" hAlign="Center" isUsingCache="false" evaluationTime="Now" hyperlinkType="Reference" hyperlinkTarget="Self" >

<reportElement

mode="Opaque"

x="0"

y="60"

width="510"

height="660"

forecolor="#000000"

backcolor="#FFFFFF"

key="image"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>jasperreports-1.2.0

<box border="Thin" borderColor="#000000" />

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

<imageExpression class="java.awt.Image">

<![CDATA[

((com.mycompany.charts.CnxPerDayChartScriptlet)$P{REPORT_SCRIPTLET}).generateChart($P{dataset},$P{chartDimension})

]]>

</imageExpression>

</image>

 

[...]

 

 

==> The generateChart() method of my CnxPerDayChartScriptlet (JRDefaultScriptlet) is responsible for generating the buffered image

 

 

##############################################

# in the html generated code, the IMG tag is :

##############################################

 

<img src="images/img_0_0_1" ..../></td>

 

 

 

 

BUT BUT BUT...

 

... this image is not created, so when the browser GET the image, the response is 404...

I don't see any images in the exploded directory of my webapp.

 

 

 

I had a look to JRHtmlExporter class, trying to debug it.

I don't understand where or when the image is generated,

(i mean when the exportReport() method of JRHtmlExporter handles the ChartScriptlet work)

 

>>> A help would be deeply welcomed.

(JasperReports version : JasperReports 1.2.0)

 

Thanx in advance.

 

 

 

 

 

By: Sanjeev Saha - sanjeevsaha

RE: webapp : image generation in HTML renderi

2006-04-25 06:47

Have you mapped the Image servlet in your web.xml? You might want to take a look at the WEB-INF/web.xml file of the webapps demo.

 

Of course, in order to see the demo, you can download the source files from http://sourceforge.net/project/showfiles.php?group_id=36382&package_id=28579

 

hth,

Sanjeev

 

 

 

 

By: bulkao - bulkao

RE: webapp : image generation in HTML renderi

2006-04-25 07:14

Thanks a lot, Sanjeev,

 

But what do you mean exactly ?

I had a look to the /demo/samples/webapp sample.

 

I don't see the reason why i need to map the "Image servlet" in my web.xml... how does it works ?

 

Any further informations ?

Thanks in advance

 

 

 

 

By: Sanjeev Saha - sanjeevsaha

RE: webapp : image generation in HTML renderi

2006-04-25 07:40

What happens in case of displaying a Jasper Report in a web app is that the exported html report is sent out in the response first, and then the browser makes separate requests for all the images that need to be displayed. Nothing unusual, just basic browser behavior since an image cannot be embedded in the html like a pdf.

 

However, in this case, if we do not have the mapping for the Image servlet, then the code <img src="images/img_0_0_1" ..../></td> will return a 404 since it will not be able to get any response from the server.

 

Simply put, the image servlet will be mapped to the "/images" url path and will return back the required images when exporting to html. Take a look at the java code for the image servlet. You might be surprised by it's simplicity.

 

When looking at the webapp demo web.xml, the mapping is "/servlets/image: which in your case is "/images". Feel free to change it as per your taste.

 

hth,

Sanjeev

 

 

 

 

By: bulkao - bulkao

RE: webapp : image generation in HTML renderi

2006-04-26 00:58

OK, Sanjeev.

 

Thanx a lot for your help.

The tips and infos you gave to me were very helpfull.

 

Best regards

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...