Jump to content

Image Display


spmkkmps

Recommended Posts

Hi,

In my jrxml i have a String parameter named "imageFile" to display image in jasper reports. How to set image to this parameter from a java file. My web application structure is, inside /src/jasper(packagename)/my java files, and jasper file in the root folder. Also tell me where i need to put the image file. Its very urgent. Please post your replies immediately. Thanks a lot.

Madhan

 

 

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

For image display when exporting to html, in many sample code these code has been included. can anyone explain me, what for the below code is added.

Map imagesMap=new HashMap();
request.getSession().setAttribute("IMAGES_MAP",imagesMap);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP,imagesMap);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image="); and what is this image?image=

whether i need to type something after image= in the fourth statement and why do we need a map object without adding anything to it. Also please tell me, in jrxml what needs to be done to include image. Please post your replies as soon as possible. If you have the jrxml and java code for image display please attach it too. Its very urgent. Thank a lot in advance.

 

Madhan!!!!

Link to comment
Share on other sites

 

When you export in HTML, JasperReports can not embed the images in the document, so you need to provide a way to get the images produces along the HTML from the server. This is done putting the images in the user session when the report is produced, and providing a mechanism to reference these images in the HTML.
The  JRHtmlExporterParameter.IMAGES_URI is the customizable url that must be used in the HTML to reference an image. It assumes you have a servlet mapped to the image uri which takes a parameter called image that will be used to find the requested image inside the session.
The servelet uses the IMAGES_MAP to find the required image.

Giulio

Link to comment
Share on other sites

Giulio,

Thanks for your reply. But i dont understand since am using jasper report for the first time. So can you please get me the application structure like where i need to place the image, jrxml and java codings and in the jrxml what needs to be done.

 

Madhan!!!!

Link to comment
Share on other sites

 

This is all arbitrary. In general the best choice is to put the jasper files and the required resources in the classpath, but you can even have a reports directory where you put the jasper files, another for the images and so on.

The jrxml files are not necessary, they are just the sources for the jasper files and are not involved in the report generation.

In the jrxml you need to say where the image is. If the image is in the classpath, you can just indicate the image name. If it is in a specific directory, you have to say where the image is. You can for instance have a parameter like IMAGES_DIR, the image expression would look like:

$P{IMAGES_DIR} + "\myImage.png"

The value for the parameter IMAGE_DIR should be  set by your application (i.e. ServletContext.getContextPath() + "/images" ).

Inside the JasperReports distribution there is a sample webapp that should help you.

Giulio

 

 

Link to comment
Share on other sites

Guilio,

It doesn't work for me. Whatever you said i tried but it works only for pdf and excel. For htmlexporter it doesn't work. Can you get me the solution to display image when exporting using htmlexporter. Anyway i need to thank for your suggestions given for my post.

 

Madhan!!!!

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