Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper Reports as Image


mkhan523

Recommended Posts

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

You could take a look at the webapp sample shipped with JR source distribution, build it, make a war file and run it on Tomcat (or any other available webserver), in order to get some idea about displaying reports in webapps. Better than exporting the report as image (this option is not available in JR) would be to export the report as HTML file, and include this file in your jsp page, using jsp:include.

For more information about displaying reports in webapps, you could browse this forum too.

Hope this helps,

sanda



Post Edited by shertage at 02/01/2011 13:11
Link to comment
Share on other sites

Hi Sanda...
Thanks for your advice it helped me alot.As said by you ,I have build the Sample application given in the web apps.But some unwanted  images are being displayed when iam trying to export JR in HTML format and then include it in my JSP. I have attached the printscreen of it.Please check it and let me know if you have any solution for this problem.

I have even pasted the code which i am using to display the jasper report in jsp page

Note: I am developing a web application in struts 1.2

Code:



Post Edited by mkhan523 at 02/02/2011 07:36



Post Edited by mkhan523 at 02/02/2011 08:35
Link to comment
Share on other sites

I tried using JasperPrintManager but i am getting the following exception


   java.lang.ClassCastException: net.sf.jasperreports.engine.JasperReport

 

Please suggest me some thing and get me out of this problem..........Plealse

 

 

 

Code:
Image p=(Image)JasperPrintManager.printPageToImage(s, pageIndex, zoom);//exception is raised at this lineAsessmentChartsMap.put(Jasper_Report,p );	session.setAttribute(JASPER_CHARTS,Jasper_Report)
Link to comment
Share on other sites

Regarding the strange images, they appear because the path to the images directory is probably invalid. You have to change the

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image=");

expression with one appropriate for your application. The IMAGES_URI parameter should contain a valid URI path to your images location.

Regarding the JasperPrintManager problem: the ClassCastException you get suggests that probably you passed a JasperReport object as the 's' method argument. The printPageToImage(...) method expects a JasperPrint object, not a JasperReport one. Try to fill your JasperReport object using the JasperFillManager, and then pass the resulting JasperPrint object to the printPageToImage(...) method.

Hope this helps,

sanda



Post Edited by shertage at 02/02/2011 09:44
Link to comment
Share on other sites

Hi Sanda...

 

I couldnt get you. what should be the image path??? i am not using any images in my jasper reports rather i am having bar charts to be displayed in the browser..... i have generated jasperReports.jrxml file using iReports 3.7.6 IDE.......

 

My knowledge about jasper is very poor.....Please help me out with this..........

 

 

 

 

Link to comment
Share on other sites

It is not about JR here, it is about HTML. Images are loaded in an HTML page from their location, using the <img src="..."> tag. The src value has to be known in order to get the report's images. So, the JRHtmlExporter should be instructed where the images in the webpage can be loaded from. In this case the IMAGES_URI parameter should point to the ImageServlet in your application.

Charts are complex objects which finally are exported as images, so they have an image like behavior. The IMAGES_URI parameter should be used as above, in this case.

More info about the IMAGES_URI and other parameters to locate images you can find here.

Hope this helps,

sanda



Post Edited by shertage at 02/02/2011 10:59
Link to comment
Share on other sites

But how do i know where will the images be generated.??? there is someting called  img_0_0_0 when i view source of the jsp page....... but i could not located where that is located in my enitre workspace.......... can you pls tell me what exactly is happening and when will  img_0_0_0 be generated and in which folder??

 

Link to comment
Share on other sites

Just thinking ... Maybe you'll need an ImageServlet (or equivalent struts Action) like the one in the webapp sample, able to resolve and serve images from a JasperPrint list object. In this case you have to configure the servlet (or action) mapping in your app, so that image-related paths to be  processed using the ImageServlet/Action.

Hope this helps,

sanda

Link to comment
Share on other sites

Hi,

 

I am using the existing ImageServlet class... and i  have mapped it in my web.xml ............ But stil facing the same problem

 

Code:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"><web-app id="WebApp_1">	<display-name>Web-Application</display-name>	<!-- Standard Action Servlet Configuration (with debugging) -->	<servlet>		<servlet-name>action</servlet-name>		<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>			<init-param>			<param-name>config</param-name>			<param-value>/WEB-INF/struts-config.xml</param-value>			</init-param>		<load-on-startup>1</load-on-startup>	</servlet>			<!--  Jasper Reports Changes - Start -->	<servlet>		<servlet-name>ImageServlet</servlet-name>		<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>	</servlet>	<!--  Jasper Reports Changes - End -->		<!-- Standard Action Servlet Mapping -->	<servlet-mapping>		<servlet-name>action</servlet-name>		<url-pattern>*.do</url-pattern>	</servlet-mapping>		<!--  Jasper Reports Changes - Start -->		<servlet-mapping>			<servlet-name>ImageServlet</servlet-name>			<url-pattern>/servlets/image</url-pattern>		</servlet-mapping>	<!--  Jasper Reports Changes - End -->			<!-- The Usual Welcome File List -->	<welcome-file-list>	   <welcome-file>index.jsp</welcome-file>	</welcome-file-list>		  <!-- Struts Tag Library Descriptors -->	  <taglib>	    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>	  </taglib>		  <taglib>	    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>	  </taglib>		  <taglib>	    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>	  </taglib>	  	  <taglib>	    <taglib-uri>/WEB-INF/struts-form.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-form.tld</taglib-location>	  </taglib>	  	  <taglib>	    <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>	  </taglib>	  	  <taglib>	    <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>	    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>	  </taglib>		  <resource-ref>	       <description>Oracle Database 11g DataSource</description>	       <res-ref-name>jdbc/oracle11g</res-ref-name>	       <res-type>oracle.jdbc.pool.OracleDataSource</res-type>	       <res-auth>Container</res-auth>  	   </resource-ref></web-app>
Link to comment
Share on other sites

Hi,

While I'm not using the struts framework, is possible that I might be wrong here. Meanwhile I found out that struts results can be configurated also as  JasperReportsResult. This class takes a specific image URL parameter: imageServletUrl.

Maybe the result should be configurated with this parameter too:

Hope this could help. If no, I have no more idea.

Regards,

sanda

Code:
<result name="success" type="jasper">   <param name="location">foo.jasper</param>   <param name="dataSource">mySource</param>   <param name="format">CSV</param>   <param name="imageServletUrl">/servlets/image?image=</param> </result>
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...