Jump to content
Changes to the Jaspersoft community edition download ×

Chart images getting overwritten


foravneet

Recommended Posts

I have two different reports containing just a chart each. I need to show them one after the other in a single jsp page ( preferably using ImageServlet)..

 

Code:

String[] allReports = {"jasper/viewedpages_top.jasper","jasper/editedpages_top.jasper"};
for(int i = 0; i< allReports.length; i++)
{
java.io.InputStream is1 = getClassLoader().getResourceAsStream(allReports(i));
//Loading my jasper file
jasperReport1 = (JasperReport) net.sf.jasperreports.engine.util.JRLoader.loadObject(is1);
//Filling the report with data from the database based on the parameters passed.
myJPrint1 = JasperFillManager.fillReport(jasperReport1, parameters, conn1.getConnection());
JRHtmlExporter exporter1 = new JRHtmlExporter();
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,myJPrint1);
exporter1.setParameter(JRExporterParameter.JASPER_PRINT, myJPrint1);
exporter1.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER,buff1);
exporter1.setParameter(JRHtmlExporterParameter.IMAGES_URI,"/jasperimage?" + "i=" + i + "&image=");
exporter1.exportReport();
}

 

when i try it the way in the code above .. the chart image in the first report is getting overwritten by the chart image in the second report..

I get the first report text properly..then the chart for the second report(instead of the one for the first report).

Below this the second report comes fine with its own chart image.

 

On seeing the html source I noticed that the image name for the chart is the same in the first report as well as the second report.. i guess that might be causing the ImageServlet to behave this way.

 

Also note that to make sure that its not a browser caching issue, I have made the two chart image URLs distinct in IMAGES_URI value.

 

Stuck on this ..Any ideas ??

Post edited by: foravneet, at: 2007/06/12 02:39

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

If you put both print objects on the session under the same name (ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE), the second object will overwrite the first one so when the first image will be requested, the servlet will actually extract it from the second report.

 

So you need to use distinct names for the two print objects on the session:

Code:

String printSessionName = ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE + i;
request.getSession().setAttribute(printSessionName, myJPrint1);
exporter1.setParameter(JRHtmlExporterParameter.IMAGES_URI,"/jasperimage?" + "jrprint=" + printSessionName + "&image="«»);

 

HTH,

Lucian

Link to comment
Share on other sites

  • 11 months later...

Hi lucianc,

My problem is exactly the same.But i am defining my exportparameters in XML file using XMLViewResolver.So how can i set my IMAGES_URI for this case.here is part of my code.

<property name="exporterParameters">

<map>

<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI">

<value/reports/image?image=</value>

</entry>

<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN">

<value type="boolean">FALSE</value>

</entry>

 

</map>

</property>

 

 

and i am setting the ImageServlet.DEFAULT_JASPER_PRINT_LIST_SESSION_ATTRIBUTE in another java file which extends JasperReportsHtmlView.I tried to set export parameters in this class even,but it's not accepting the values here.here is my code

 

Map map=new HashMap();

map.put(net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI, /reports/image?" + "jrprint=" + tempSession+ "&image=");

map.put(net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,false);

this.setExporterParameters(map);

 

session.setAttribute(ImageServlet.JASPER_PRINT_REQUEST_PARAMETER,populatedReport);

 

 

Please help to resolve.

Link to comment
Share on other sites

Hi lucianc,

 

Sorry here is updated ,I found typo mistakes in the above message.

 

My problem is exactly the same.But i am defining my exportparameters in XML file using XMLViewResolver.So how can i set my IMAGES_URI for this case.here is part of my code.

 

<property name="exporterParameters">

 

<map>

 

<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI">

 

<value/reports/image?image=</value>

 

</entry>

 

<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN">

 

<value type="boolean">FALSE</value>

 

</entry>

 

 

 

</map>

 

</property>

 

 

 

 

 

and i am setting the ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE in another java file which extends JasperReportsHtmlView.I tried to set export parameters in this class even,but it's not accepting the values here.here is my code

 

 

 

Map map=new HashMap();

 

map.put(net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI, /reports/image?" + "jrprint=" + tempSession+ "&image=");

 

map.put(net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,false);

 

this.setExporterParameters(map);

 

 

 

Please help to resolve.

Link to comment
Share on other sites

dear_sunny wrote:

and i am setting the ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE in another java file which extends JasperReportsHtmlView.I tried to set export parameters in this class even,but it's not accepting the values here.

 

Looking at Spring's JasperReportsHtmlView, it seems to take export parameters from the model map. Try to set the export parameter in the model map:

Code:

model.put(JRHtmlExporterParameter.IMAGES_URI, "/reports/image?jrprint=" + tempSession + "&image="«»);

 

Note the "jrprint" parameter value must match the name of the JasperPrint object on the session.

 

Regards,

Lucian

Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...

Hi Luckian,

 

I am facing exactly the same problem and your answer looks compelling to me. But when I am doing the same as you suggested I am getting no images. I get "No JasperPrint documents found on the HTTP session."

 

Everything looks fine to me but my images get overwritten as they are in the same session(may be).

 

I would appreciate if you can throw more details on your solution.

 

Thanks

Amit

Link to comment
Share on other sites

  • 8 months later...

lucianc
Wrote:

If you put both print objects on the session under the same name (ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE), the second object will overwrite the first one so when the first image will be requested, the servlet will actually extract it from the second report.

So you need to use distinct names for the two print objects on the session:
Code:


HTH,
Lucian

Thanks Lucian, that was very helpful.

Link to comment
Share on other sites

  • 3 years later...

Hi,

 

I have the same problem and I am trying to use this code, but it doesn't work for me. The problem is that browser doesn't find the url of images.

String printSessionName = ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE + i;request.getSession().setAttribute(printSessionName, myJPrint1);exporter1.setParameter(JRHtmlExporterParameter.IMAGES_URI,"/jasperimage?" + "jrprint=" + printSessionName + "&image="); [/code]

 

I'm wondering if it's necessary to change other part of the code so that "jrprint"  attribute of the url can be recognized.

Any helps would be appreciated!

Link to comment
Share on other sites

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