?
Solved

JSP -> Servlet -> Jasper

Posted on 2006-04-11
8
Medium Priority
?
1,774 Views
Last Modified: 2008-01-09
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....

0
Comment
Question by:LeanMoreTryMore
  • 4
  • 3
8 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 16433512
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 16433522
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
 

Author Comment

by:LeanMoreTryMore
ID: 16433658
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 200 total points
ID: 16433828
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
 
LVL 2

Accepted Solution

by:
leogc earned 1400 total points
ID: 16434227
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
 

Author Comment

by:LeanMoreTryMore
ID: 16442523
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 16475050
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
 

Author Comment

by:LeanMoreTryMore
ID: 16523387
Would David give me a simple program to use tag to diaplay it into the JSP?

Please
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question