:::Preciso disso:::

4 respostas
kartler

Amigos Ajudem-me por favor… tenho o seguinte .XML que dentro do ireport eu gero um relatório que traz os usuarios da base de dados…

Como eu faço para chamar o relatorio a partir de uma pagina jsp por favor coloquem o código pra mim…e este relatorio deve vir de uma tabela em meu DB…

<?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="Teste" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <queryString><![CDATA[ select * from userpetro ]]></queryString> <field name="nome" class="java.lang.String"/> <field name="chave" class="java.lang.String"/> <variable name="test" class="java.lang.String" resetType="None" calculation="Nothing"> <variableExpression><![CDATA["test"]]></variableExpression> <initialValueExpression><![CDATA["test" ]]></initialValueExpression> </variable> <title> <band height="50"> <staticText> <reportElement mode="Transparent" x="61" y="5" width="412" height="40" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Center" verticalAlignment="Top" lineSpacing="Single"> <font fontName="" pdfFontName="Times-Bold" size="30" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1250" isStrikeThrough="false" /> </textElement> <text><![CDATA[Relatorio Teste]]></text> </staticText> <line direction="TopDown"> <reportElement mode="Opaque" x="0" y="48" width="534" height="0" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="2Point" fill="Solid" /> </line> <line direction="TopDown"> <reportElement mode="Opaque" x="0" y="3" width="534" height="0" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="2Point" fill="Solid" /> </line> </band> </title> <pageHeader> <band height="9"> </band> </pageHeader> <columnHeader> <band height="15"> <rectangle> <reportElement mode="Opaque" x="0" y="0" width="535" height="15" forecolor="#000000" backcolor="#808080" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="None" fill="Solid" /> </rectangle> <line direction="BottomUp"> <reportElement mode="Opaque" x="0" y="0" width="535" height="0" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" /> </line> <line direction="BottomUp"> <reportElement mode="Opaque" x="0" y="15" width="535" height="0" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" /> </line> <staticText> <reportElement mode="Transparent" x="1" y="1" width="267" height="15" forecolor="#FFFFFF" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="" pdfFontName="Times-Roman" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <text><![CDATA[nome]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="267" y="0" width="267" height="15" forecolor="#FFFFFF" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="" pdfFontName="Times-Roman" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <text><![CDATA[chave]]></text> </staticText> </band> </columnHeader> <detail> <band height="22"> <line direction="TopDown"> <reportElement mode="Opaque" x="0" y="19" width="535" height="0" forecolor="#808080" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" /> </line> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="0" y="2" width="267" height="14" forecolor="#800000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="Times-Roman" pdfFontName="Times-Roman" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{nome}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="267" y="0" width="267" height="18" forecolor="#800000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="Times-Roman" pdfFontName="Times-Roman" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{chave}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="0"> </band> </columnFooter> <pageFooter> <band height="27"> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="325" y="4" width="174" height="19" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Right" verticalAlignment="Top" lineSpacing="Single"> <font fontName="Helvetica" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Page " + $V{PAGE_NUMBER} + " of "]]></textFieldExpression> </textField> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" > <reportElement mode="Transparent" x="499" y="4" width="36" height="19" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="Helvetica" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression> </textField> <line direction="TopDown"> <reportElement mode="Opaque" x="1" y="3" width="535" height="0" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <graphicElement stretchType="NoStretch" pen="2Point" fill="Solid" /> </line> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="1" y="6" width="209" height="19" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="Times-Roman" pdfFontName="Times-Roman" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="0"> </band> </summary> </jasperReport>
Obrigado…

4 Respostas

duardor

Kra o codigo especificamente eu nao me lembro…
Mas eh o seguinte, mais ou menos (req eh o request, res eh o response):

InputStream in = getClass().getResourceAsStream("/relatorios/meuRelatorio.jasper"); //NAO ME LEMBRO MUITO BEM DESSA LINHA

ResultSet dadosDoBanco = pegaValores();//ASSUMA ISSO COMO OS VALORES DO BANCO

JRResultSetDataSource dadosJasper = new JRResultSetDataSource(dadosDoBanco);

OutputStream out = res.getOutputStream();

JasperRunManager.runReportToPdfStream(in,out,null,dadosJasper);
Bom basicamente eh isso…

A linha do InputStream eu nao tenho muita certeza, basta vc ter certeza de ter um input stream com o arquivo .jasper correto.

Uma coisa q acontecia comigo eh q eu nao podia fechar a conexao nem o statement antes do relatorio ser emitido… E lembrando tb que vc nao pode ‘comitar’ nenhuma informacao para o usuario antes do report (e nem depois! :-P)

Existe um metodo semelhante que usa Collection ao invés de ResultSet mas eu nunca utilizei. Caso vc queira passar algum parametro vc pode usar um map, passando ele no terceiro argumento do metodo JasperRunManager.runReportToPdfStream(in,out,MAP,dadosJasper);

Eh isso espero ter ajudado!!!

Qq coisa pergunta ai!!!

kartler

Faz o seguinte mano se for possivel…

Gera um exemplo simples mesmo e me manda o código completo se for possivel eu fiocarei mui agradeciso

cv1

Pô, que folga, hein kartler?

kartler

:oops: Mano tô queimando pestanas noites de sono… realmente não tenho sido bem sucedido HELP… :?

Criado 7 de julho de 2003
Ultima resposta 7 de jul. de 2003
Respostas 4
Participantes 3