简体   繁体   English

在apache服务器上部署war文件时,jasper报告不起作用

[英]Jasper Report Not Working When Deploy war file on apache server

I have created jasper report and it woks perfectly on netbean but when i build war file and deploy it on apache server then it not works.... 我已经创建了jasper报告,它在netbean上完全可以正常工作,但是当我构建war文件并将其部署到apache服务器上时,它就无法工作。

I Tried So hard on this problem spend whole day but didn't find any solution please help me out to solve this 我在这个问题上尝试了整整一天,但是没有找到任何解决方案,请帮助我解决这个问题

Here is My Code 这是我的代码

String loc = "C:\\Program Files\\report\\
public void CustBillPrint(String BillNo) {
        String path = loc + "customer-bill-1.jasper";
        Map param = new HashMap();
        param.put("billno", BillNo);
        try {
            JasperPrint jasperPrint = JasperFillManager.fillReport(path, param, con);
            JasperViewer.viewReport(jasperPrint, false);

        } catch (JRException e) {
            System.out.println(e);
        }
    }

I already tried many ways are as follows: 我已经尝试了很多方法,如下所示:

InputStream path = this.getClass().getResourceAsStream("report/farmpati-1.jasper");

InputStream path = new FileInputStream(new File("web/report/farmpati-1.jasper"));

InputStream path = new FileInputStream(new File("").getAbsolutePath() + "/reports/logReport.jrxml");

String path = System.getProperty("user.dir") + "\\report\\";

String path = new File(".").getCanonicalPath() + "/web/report/";

And All This Alternative Work in NetBan But not working on apache when deploy as war 以及NetBan中的所有其他替代方法,但部署为战争时无法在apache上运行

Use ServletContext 's getResourceAsStream() method to read a resource in a jar file in any web application.. 使用ServletContextgetResourceAsStream()方法读取任何Web应用程序中jar文件中的资源。

ServletContext context = getServletContext();
InputStream is = context.getResourceAsStream("/farmpati-1.jasper");

please have look into Reading files in jar 请看看在jar中读取文件

I have found a possible answer on community.jaspersoft.com: http://community.jaspersoft.com/questions/536218/resolved-problem-subreport-reference-after-exporting-ireport-jasperserver 我在community.jaspersoft.com上找到了可能的答案: http : //community.jaspersoft.com/questions/536218/resolved-problem-subreport-reference-after-exporting-ireport-jasperserver

"In the report that's working, the subreport isn't just in the repository as its own report on the same level as the main report. There is also a copy of that subreport in the Resources "folder" for the main report." “在正在运行的报表中,子报表不只是与自己的报表一样位于存储库中,而且与主报表位于同一级别。主报表的资源“文件夹”中也有该子报表的副本。”


That topic contains more than 1 solution, one of them is a resolved topic here on Stackoverflow: JasperServer: Unable to locate the subreport exception (warning: this is a very long, but detailed, read) 该主题包含多个解决方案,其中一个是在Stackoverflow上已解决的主题: JasperServer:无法找到子报表异常 (警告:这是一个很长但很详细的阅读文章)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM