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

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.

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

This worth to be looked at


"Jasper report itself come with some nice samples and tutorials which are available in
and samples which are located in "Jasper report folder"\demo\samples"
taken from the URL above

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

Upgrade your Question Security!

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

Oh now I get you.

Try to read this link. It may be useful to you.

Look at the bottom messages

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.setHeader("Expires", "");
                response.setHeader("Cache-Control", "");
                response.setHeader("Pragma", "");
                ouputStream.write(bytes, 0, bytes.length);
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.

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


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

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

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

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.