Jump to content
We've recently updated our Privacy Statement, available here ×

Empty pdf with Struts 1


mackensen

Recommended Posts

Hello,

I have a web app with Struts 1.2.9 and JasperReport 3.5.2.

The problem is that when I create an Action to generate a pdf I get an empty pdf. I created the .jrxml file with iReport 3.5.2 and I put on it just a static text.

I also tried to export to XML. I get the XML tree but there's only the name of the report so I presume that the path to the report is ok, I mean, the application gets the right report file.

Below is the code:

Thanx,
Mack
 

 

Code:
public ActionForward printPdf(ActionMapping mapping, ActionForm  form,            HttpServletRequest request, HttpServletResponse response)            throws Exception {                      ServletOutputStream out=response.getOutputStream();  //i also tried with OutputStream                response.setContentType( "application/pdf" );              JasperDesign jasperDesign=null;        JasperReport jasperReport=null;        String reportFile="";         reportFile=this.getServlet().getServletConfig().getServletContext().getRealPath("/reports/Print_indComm.jrxml");        Map parameters_header=null;                parameters_header=this.getParametersHeaderPdf(idComm);   //this method and parameter are defined             try {        jasperDesign = JRXmlLoader.load(reportFile);               jasperReport = JasperCompileManager.compileReport(jasperDesign);                JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters_header);                   JasperExportManager.exportReportToPdfStream(jasperPrint, out);                out.flush();        out.close();        }        catch (Exception ex)        {            String connectMsg = "Could not create the report " + ex.toString() + " " + ex.getLocalizedMessage();            response.setContentType("text/html;charset=UTF-8");            PrintWriter out1 = response.getWriter();            out1.println(connectMsg);            out1.close();        }              return mapping.getInputForward();    }
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...