JasperReports报告没有在Spring MVC应用程序中弹出

时间:2012-01-17 07:39:21

标签: java spring spring-mvc jasper-reports ireport

我在我的springMVC网站上整合了JasperReports。 它在我的本地系统中运行良好,但是当我将该网站上传到服务器报告时生成但是它没有弹出,因为它在我的本地系统中弹出。

我正在使用iReport 4.1

在上传网站之前,我还会更改报告路径。 报告在目标文件夹中生成,但不会自动显示。

这是我的代码:

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();

2 个答案:

答案 0 :(得分:1)

首先使用绝对路径的原因。我认为你应该使用相对路径(ServletContext.getRealPath())。      第二,这段代码是什么

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();

它不会在网页浏览器中显示。要在浏览器中查看报告,请将pdf写入http servletresponse并相应地设置http标头。

答案 1 :(得分:0)

如果您使用弹簧3,这可能会有所帮助

    @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

            }
        }
    }