0

Zasper report is not working.

asked 2012-07-10 07:29:01 +0800

swati123 gravatar image swati123
66

hi..
I am working with jasper reports.i downloaded jaspersoft ireport 4.6 and created report.but I am unable to connect with zul.
Please tel me how to connect with zul file.
Please help me .

Thanks ,

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-07-10 07:34:29 +0800

swati123 gravatar image swati123
66

hi guys..
I have written the follwing code.

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<?page style="height:100%" ?>
<window width="100%" height="100%">
<borderlayout height="100%">
<north maxsize="24" size="24" border="0">
<button label="Report!" onClick="doReport()"/>
</north>
<center border="none" flex="true">
<iframe id="report" />
</center>
</borderlayout>
<zscript lanuage="Java">

package net.ensode.jasperbook;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JasperRunManager;



public class doReportServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
Connection connection;
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream reportStream =getServletConfig().getServletContext().getResourceAsStream("/reports/test.jasper");
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection ("jdbc:mysql://localhost:3306/stock",user="root", password="123456");
JasperRunManager.runReportToPdfStream(reportStream,
servletOutputStream, new HashMap(), connection);
connection.close();
response.setContentType("application/pdf");
servletOutputStream.flush();
servletOutputStream.close();
}
catch (Exception e)
{
// display stack trace in the browser
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print(stringWriter.toString());
}
}

}
</zscript>

</window>
</zk>

please help me ..As i am weak in java.
Thanks.

link publish delete flag offensive edit

answered 2012-07-11 06:41:42 +0800

samchuang gravatar image samchuang
4084 4

updated 2012-07-11 06:43:48 +0800

hi, you can refer to demo and it's source code
http://www.zkoss.org/zkdemo/reporting/jasperreport

or doc
http://books.zkoss.org/wiki/ZK%20Component%20Reference/Diagrams%20and%20Reports/Jasperreport

smalltalk
http://books.zkoss.org/wiki/Small_Talks/2012/April/Create_a_Report_with_ZK_using_iReport_and_JasperReports

link publish delete flag offensive edit

answered 2012-07-11 10:54:42 +0800

swati123 gravatar image swati123
66

Thanks a lot ..samchuang.
It's working.

link publish delete flag offensive edit

answered 2012-07-12 13:10:42 +0800

javaenthu gravatar image javaenthu
141 2

@ Swati : Are you facing any connection leak?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-07-10 07:29:01 +0800

Seen: 303 times

Last updated: Jul 12 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More