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

发布于 2024-12-27 07:09:37 字数 1212 浏览 1 评论 0原文

我在我的 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();

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自控 2025-01-03 07:09:37

首先为什么你使用绝对路径。我认为你应该使用相对路径(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 servlet 响应并相应地设置 http 标头。

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.

居里长安 2025-01-03 07:09:37

如果你使用 spring 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

            }
        }
    }

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

            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文