Rushik Parikh
Rushik Parikh

Reputation: 613

The JasperReports report not popping up in Spring MVC application

I integrated JasperReports in my springMVC website. It was running fine in my local system but when I upload that website to server report is getting generated but it is not popping up as it was popping up in my local system.

I'm using iReport 4.1

Before uploading website I also change path for report. Report is generated at destination folder but it is not displayed automatically.

This is my code:

jasperReport = JasperCompileManager.compileReport("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.jrxml");
//JasperFillManager.fillReportToFile("D:\\reports\\test.jasper", jasperParameter, rsss);
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, rsss);
//JasperPrintManager.printReport(jasperPrint,true);

JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf");
//        new mainpage(getTitle());

if ((new File("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf")).exists()) {
    Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf");
    p.waitFor();

Upvotes: 0

Views: 2282

Answers (2)

Moinul Hossain
Moinul Hossain

Reputation: 2206

If u r using spring 3 this might help

    @Controller
    @RequestMapping(value="/report")
    public class ReportsController
    {
        @RequestMapping(value="/getMyReport", method=RequestMethod.GET)
        public void runReport(@RequestParam("someParam")String someParam,@RequestParam("someOtherParam")String someOtherParam,HttpServletRequest request,HttpServletResponse response)
        {
            InputStream is = null ;
            is = request.getSession().getServletContext().getResourceAsStream("/WEB-INF/reports/myReport.jasper");
            Map paramMap = new HashMap();
            paramMap.put("someParam", someParam);
            paramMap.put("someOtherParam", someOtherParam);
            response.setContentType("application/pdf");
            response.setHeader("Content-Disposition", "inline; filename=myReport.pdf");
            try {
                Connection connection =getDatabaseConnection();//let this method returns a database connection
                JasperRunManager.runReportToPdfStream(is, response.getOutputStream(), paramMap, connection);
                response.getOutputStream().flush();
                response.getOutputStream().close();
            }
            catch (Exception e)
            {
               //may be some Exception handling

            }
        }
    }

Upvotes: 0

ayengin
ayengin

Reputation: 1596

First why you are using absolute path.I think you should use relative path (ServletContext.getRealPath()). Second ,What is for this code

Process p = Runtime
       .getRuntime()
       .exec("rundll32 url.dll,FileProtocolHandler C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf");
    p.waitFor();

It will not show in web browser ofcourse.For viewing report in browser write pdf to http servletresponse and set http headers accordingly.

Upvotes: 1

Related Questions