Jump to content
Changes to the Jaspersoft community edition download ×

Servlet and JasperReports

2004 IR Help

Recommended Posts

By: Alan Shiers - ashiers

Servlet and JasperReports

2005-05-30 13:09



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:




<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style type="text/css">

a {text-decoration: none}



<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>





So, the servlet is returning something, just not my report! Any idea what might be causing the problem?





public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException


Connection connection = null;

System.out.println("entering doPost");


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);




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");





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,



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=");


System.out.println("the end");





catch (JRException e)




Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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...