Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JasperPrint应用程序崩溃_Java_Jsf 2_Jasper Reports - Fatal编程技术网

Java JasperPrint应用程序崩溃

Java JasperPrint应用程序崩溃,java,jsf-2,jasper-reports,Java,Jsf 2,Jasper Reports,在我的web应用程序中,我使用JasperReports生成一些报告。在我的托管bean中,我有以下报告生成代码: public void generateReport(ActionEvent e) { // Inside a Managed Bean try { pathReport = ReportHelper.reportPath(FacesContext.getCurrentInstance(), "rep_attendees.jasper");

在我的web应用程序中,我使用JasperReports生成一些报告。在我的托管bean中,我有以下报告生成代码:

public void generateReport(ActionEvent e) { // Inside a Managed Bean
    try {
        pathReport = ReportHelper.reportPath(FacesContext.getCurrentInstance(), "rep_attendees.jasper");
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("EVENT_ID", getEvent().getId());
        param.put("START_DATE", null);
        param.put("END_DATE", null);
        try {
            Properties connectionProps = new Properties();
            connectionProps.put("user", "root");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/MyDB", connectionProps);
            pdfFile = ReportHelper.generateReport(pathRelatorio, parametros, con);
        } catch (Exception ex) {
            log.error(ex.getMessage());
        }
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }

}
public void generateReport(ActionEvent e){//在托管Bean中
试一试{
pathReport=ReportHelper.reportPath(FacesContext.getCurrentInstance(),“rep_attendes.jasper”);
Map param=new HashMap();
参数put(“EVENT_ID”,getEvent().getId());
参数put(“开始日期”,空);
参数put(“结束日期”,空);
试一试{
Properties connectionProps=新属性();
connectionProps.put(“用户”、“根”);
Connection con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/MyDB“,连接道具);
pdfFile=ReportHelper.generateReport(pathRelatorio、ParameterOS、con);
}捕获(例外情况除外){
log.error(例如getMessage());
}
}捕获(例外情况除外){
log.error(例如getMessage());
}
}
ReportHelper的代码:

public class ReportHelper {

    private static final Logger log = Logger.getLogger(RelatorioHelper.class);


    public static byte[] generateReport(String path, Map<String, Object> param, Connection con) throws FileNotFoundException, JRException, Exception {

        JasperReport rep = null; // 1
        JasperPrint print = null; // 2
        byte[] pdf = null; // 3
        try {
            rep = buildReport(path); // 4
            print = loadReport(rep, param, con); // 5 NEVER RETURNS
            pdf = JasperExportManager.exportReportToPdf(print); // 6 Don't reach this line
        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }
        return pdf;
    }

    public static String reportPath(FacesContext context, String reportName) {
        String repPath = ((ServletContext) context.getExternalContext().getContext()).getRealPath("/resources/reports/") + "/" + reportName;
        return repPath;
    }

    private static JasperReport buildReport(String path) throws FileNotFoundException, JRException {
        return (JasperReport) JRLoader.loadObject(new File(path));
    }

    private static JasperPrint loadReport(JasperReport report, Map<String, Object> param, Connection con) throws JRException {
        return JasperFillManager.fillReport(report, param, con);
    }
}
公共类ReportHelper{
私有静态最终记录器log=Logger.getLogger(RelatorioHelper.class);
公共静态字节[]generateReport(字符串路径、映射参数、连接con)引发FileNotFoundException、JREException、Exception{
JasperReport rep=null;//1
JasperPrint print=null;//2
字节[]pdf=null;//3
试一试{
rep=buildReport(路径);//4
print=loadReport(rep、param、con);//5永远不会返回
pdf=jaspeexportmanager.exportReportToPdf(打印);//6不要到达此行
}捕获(例外e){
log.error(例如getMessage());
投掷e;
}
返回pdf;
}
公共静态字符串报告路径(FacesContext上下文,字符串报告名称){
字符串repPath=((ServletContext)context.getExternalContext().getContext()).getRealPath(“/resources/reports/”)+“/”+reportName;
返回路径;
}
私有静态JasperReport buildReport(字符串路径)抛出FileNotFoundException、JREException{
return(JasperReport)JRLoader.loadObject(新文件(路径));
}
私有静态JasperPrint loadReport(JasperReport、Map param、Connection con)引发异常{
返回JasperFillManager.fillReport(报告、参数、con);
}
}
以下是报告xml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="SisEventos_RelatorioEvento" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="DATA_INICIO" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="DATA_TERMINO" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="ID_EVENTO" class="java.lang.Integer" isForPrompting="false">
    <defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select idt_evento, nme_evento, dta_inicio_evento, dta_termino_evento, nme_participante, eml_participante from tb_inscricao as t1
 inner join tb_evento as t2 on t1.cod_evento = t2.idt_evento
 inner join tb_participante as t3 on t1.cod_participante = t3.idt_participante
  where (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is not null and $P{DATA_TERMINO} is not null and t2.dta_inicio_evento between $P{DATA_INICIO} and      $P{DATA_TERMINO}) or (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is null and $P{DATA_TERMINO} is not null and t2.dta_termino_evento <= $P{DATA_TERMINO}) or     (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is not null and $P{DATA_TERMINO} is null and t2.dta_inicio_evento >= $P{DATA_INICIO}) or (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is null and $P{DATA_TERMINO} is null)
group by t2.nme_evento order by t2.dta_inicio_evento asc;]]>
</queryString>
<field name="idt_evento" class="java.lang.Integer"/>
<field name="nme_evento" class="java.lang.String"/>
<field name="dta_inicio_evento" class="java.sql.Timestamp"/>
<field name="dta_termino_evento" class="java.sql.Timestamp"/>
<field name="nme_participante" class="java.lang.String"/>
<field name="eml_participante" class="java.lang.String"/>
<group name="gEventos">
    <groupExpression><![CDATA[$F{nme_evento}]]></groupExpression>
    <groupHeader>
        <band height="42">
            <rectangle>
                <reportElement x="25" y="21" width="530" height="20" forecolor="#666666" backcolor="#666666"/>
            </rectangle>
            <staticText>
                <reportElement x="35" y="21" width="267" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[Participante]]></text>
            </staticText>
            <staticText>
                <reportElement x="302" y="21" width="186" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[E-mail]]></text>
            </staticText>
            <staticText>
                <reportElement x="488" y="21" width="68" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[Presente]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="1" width="270" height="20"/>
                <textElement>
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Evento: " + $F{nme_evento}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="270" y="12" width="280" height="1"/>
            </line>
        </band>
    </groupHeader>
    <groupFooter>
        <band height="50"/>
    </groupFooter>
</group>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="60" splitType="Stretch">
        <rectangle>
            <reportElement x="0" y="0" width="200" height="60" forecolor="#E6E6E6" backcolor="#E6E6E6"/>
        </rectangle>
        <staticText>
            <reportElement x="0" y="0" width="200" height="60" forecolor="#666666" backcolor="#FFFFFF"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font fontName="Arial" size="30"/>
            </textElement>
            <text><![CDATA[SisEventos]]></text>
        </staticText>
        <staticText>
            <reportElement x="200" y="35" width="355" height="25"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font fontName="Arial" size="18" isBold="true" isUnderline="false"/>
            </textElement>
            <text><![CDATA[Relatório de Participantes dos Eventos]]>        </text>
        </staticText>
        <line>
            <reportElement x="200" y="59" width="355" height="1"/>
        </line>
    </band>
</title>
<pageHeader>
    <band height="30" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="5" width="80" height="20"/>
            <textElement>
                <font isBold="true"/>
            </textElement>
            <text><![CDATA[Filtro: ]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
            <reportElement x="80" y="5" width="475" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA["Data de início: " + (($P{DATA_INICIO} != null) ? $P{DATA_INICIO}.toLocaleString().substring(0, 10) : "Não informada") + " - Data de término: " + (($P{DATA_TERMINO} != null) ? $P{DATA_TERMINO}.toLocaleString().substring(0, 10) : "Não informada")]]></textFieldExpression>
        </textField>
    </band>
</pageHeader>
<columnHeader>
    <band splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="20" splitType="Stretch">
        <rectangle>
            <reportElement x="25" y="0" width="530" height="20" forecolor="#E6E6E6" backcolor="#E6E6E6">
                <printWhenExpression><![CDATA[$V{COLUMN_COUNT}%2==0]]></printWhenExpression>
            </reportElement>
        </rectangle>
        <textField isStretchWithOverflow="true">
            <reportElement x="34" y="0" width="267" height="20"/>
            <textElement textAlignment="Left" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$F{nme_participante}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="302" y="0" width="185" height="20"/>
            <textElement verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$F{eml_participante}]]></textFieldExpression>
        </textField>
        <rectangle radius="10">
            <reportElement x="500" y="2" width="15" height="15"/>
        </rectangle>
    </band>
</detail>
<columnFooter>
    <band splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="20" splitType="Stretch">
        <textField>
            <reportElement x="355" y="0" width="200" height="20"/>
            <textElement textAlignment="Right" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Página "+$V{PAGE_NUMBER}+" de "+ $V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" pattern="EEE, dd MMM yyyy - HH:mm:ss" isBlankWhenNull="true">
            <reportElement x="0" y="0" width="200" height="20"/>
            <textElement verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Impresso em: " + new java.util.Date().toLocaleString()]]></textFieldExpression>
        </textField>
        <line>
            <reportElement x="0" y="0" width="555" height="1"/>
        </line>
    </band>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>
</jasperReport>

=$P{DATA_INICIO})或(t1.cod_evento=$P{ID_evento}和$P{DATA_INICIO}为空,$P{DATA_TERMINO}为空)
按t2.nme\U事件分组按t2.dta\U inicio\U事件asc排序;]>

当他到达第4行时,一件奇怪的事情发生了:一个名为org.apache.cataline.startup.bootstrap的工具在我的Dock中打开。但当他到达第5行并执行时,应用程序似乎卡住了,没有响应。好的,另一件事是:我正在使用hibernate。如何从Hibernate获取连接对象(通过JasperFillManager.fillReport(rep,param,con))呢?

ramkitech.com发现了错误!在我的应用程序中,我使用Maven,并且使用以下依赖项工件导入jasper reports库:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>4.7.0</version>
</dependency>

net.sf.jasperreports
jasperreports
4.7.0
但我还需要以下依赖项:

 <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <version>2.1.7</version>
 </dependency> 

com.lowagie
文字
2.1.7
如果您在报告中使用groovy作为一种语言(如我的情况),则需要添加:

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>1.7.5</version>
</dependency>

org.codehaus.groovy
groovy all
1.7.5