2004 IR Help Posted August 21, 2006 Share Posted August 21, 2006 By: Alan Shiers - ashiers Servlet and JasperReports 2005-05-30 13:09 HELP! My servlet code is able to execute without any exceptions but my report doesn't appear in the browser at all! I had a look at the source response from the servlet and it looks like this: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style type="text/css"> a {text-decoration: none} </style> </head> <body text="#000000" link="#000000" alink="#000000" vlink="#000000"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr><td width="50%"> </td><td align="center"> </td><td width="50%"> </td></tr> </table> </body> </html> So, the servlet is returning something, just not my report! Any idea what might be causing the problem? Alan public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { Connection connection = null; System.out.println("entering doPost"); res.setContentType("text/html"); PrintWriter out = res.getWriter(); String CompanyID = req.getParameter("CompanyID"); String CourseID = req.getParameter("CourseID"); String SubmissionDate = req.getParameter("SubmissionDate"); String DaysMissedAverage = "1-3"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date today = new java.util.Date(); String ReportDate = sdf.format(today); String ReportingServletURL = res.encodeRedirectURL("/scholastic/CourseEvalReportProcessor"); //create a map of parameters to pass to the report. Map<String, String> parameters = new HashMap<String,String>(); parameters.put("CompanyID", CompanyID); parameters.put("CourseID", CourseID); parameters.put("SubmissionDate", SubmissionDate); parameters.put("DaysMissedAverage", DaysMissedAverage); parameters.put("ReportDate", ReportDate); parameters.put("ReportingServletURL", ReportingServletURL); try { Context ctx = new InitialContext(); if(ctx == null ) throw new Exception("No Context available..."); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Scholastic"); if (ds != null) { connection = ds.getConnection(); if(connection != null) { System.out.println("got connection"); //get the pre-compiled report ServletContext context = this.getServletConfig().getServletContext(); InputStream inputStream = mvcs.CourseEvalReportProcessor.class.getResourceAsStream("/reports/CourseEvalReport.jasper"); if(inputStream == null) { System.out.println("unable to load report file"); return; } else { System.out.println("creating report..."); JasperPrint jasperPrint = null; JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream); System.out.println("got jasper report..."); //create JasperPrint using fillReport() method jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection); System.out.println("got jasper print"); JRHtmlExporter exporter = new JRHtmlExporter(); //Send the report back out using PrintWriter object Map imagesMap = new HashMap(); req.getSession().setAttribute("IMAGES_MAP", imagesMap); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); exporter.exportReport(); System.out.println("the end"); } } } } catch (JRException e) { ... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now