JSP -> Servlet -> Jasper

I have developed a report using Jasper. This report will be invoked from the JSP page which sends the requests to Servlet.

My question is how to i tell the servlet to run the Jasper report and send the report back to the user...

Please give me the process flow how to tackle this problem if anyone who has done this before.

I think this is very common requirement. The web page is allowed the user to run the report. Once the report is generated, the report is sent it back to the JSP page....

LeanMoreTryMoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suprapto45Commented:
I think that you need to look at the Jasper documentation.

This worth to be looked at
http://ensode.net/jasperreports_pdf_send_to_browser.html

David
0
suprapto45Commented:
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=64&t=001343

"Jasper report itself come with some nice samples and tutorials which are available in
http://jasperreports.sourceforge.net/tutorial/index.html
and samples which are located in "Jasper report folder"\demo\samples"
taken from the URL above

David
0
LeanMoreTryMoreAuthor Commented:
I have read some documents.

I want to know how to invoke a jasper report from within Servlet and how to send it back to the user (JSP client)?

I think the attached link shows us how to build a jasper report but do not answer my question

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

suprapto45Commented:
Oh now I get you.

Try to read this link. It may be useful to you.
http://forums.codecharge.com/posts.php?post_id=53893

Look at the bottom messages

David
0
leogcCommented:
Compile the jasper report to get the .jasper file.Then in servlet u can write the following code to generate the report:
               JasperPrint jasperPrint = JasperFillManager.fillReport(jasperFileName,
                        parameters, new JRBeanArrayDataSource(beanName));

               byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
               String pdfFileName = strReportFileName + ".pdf";
                ServletOutputStream ouputStream = response.getOutputStream();
                  response.setContentType("application/pdf");
                  response.setContentLength(bytes.length);
                response.setHeader("Content-Disposition","attachment;filename="+pdfFileName);
                response.setHeader("Expires", "");
                response.setHeader("Cache-Control", "");
                response.setHeader("Pragma", "");
                response.setContentLength(bytes.length);
                ouputStream.write(bytes, 0, bytes.length);
                  ouputStream.flush();
                  ouputStream.close();
Note for compiling u r servlet u need to have the jar file provided by jasper reports.This approach uses JRBeanArrayDataSource.For this u should first create a bean with properties.These properties will be represented as columns of report.Compile u r bean.Make a jar.Using this jar and specifying u r field names in jasper as column names
compile u r jrxml file to get the jasper file.Pass the jasper file name to JasperFillManager.fillReport() as shown above.Then u will be able to generate the report.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeanMoreTryMoreAuthor Commented:
Thanks for you guys

Is it the common way to be used in commerical web application? I means always use Servlet technology to generate Jasper report and send it back to web client.???

0
suprapto45Commented:
Hi,

>>"Is it the common way to be used in commerical web application?"
I am not sure but I think so. I can't find any other way to do it. Alternatively, you can create a custom tag for it and use this tag to display it into your JSP (that would be neater).

David
0
LeanMoreTryMoreAuthor Commented:
Would David give me a simple program to use tag to diaplay it into the JSP?

Please
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.