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

ImageServlet displays wrong image (from prior run)


toltsch

Recommended Posts

Hello,

 

I'm having an issue with net.sf.jasperreports.j2ee.servlets.ImageServlet caching images from prior runs of a report with 3D pie charts.

 

I'm using the HtmlExporter to output the report.

 

I'm seeing the same image tag used in previous runs which incorrectly serves up the wrong image.

 

I have a calendar control which runs the Jasper report when you click on a date.

 

I'm seeing this line used in other report runs and when I see this happening it displays the wrong image:

 

<img src="http://pc-2ua62618sz:9080/jenasys/servlet/net.sf.jasperreports.j2ee.servlets.ImageServlet?image=img_0_0_2" border="0" style="height: 170px" usemap="#map_0_0_2" alt=""/>

 

Here is the code used to output the report:

 

public static void renderForm(HttpServletRequest request, HttpServletResponse response, ServletContext context, Object[] objParms) throws Exception {

JasperPrint print = null;

String inputType = null;

String reportFileName = null;

String recordPath = null;

Document xmlDocument = null;

Connection jdbcConnection = null;

 

response.setContentType("text/html");

PrintWriter out = response.getWriter();

 

try

{

inputType = ((String) objParms[0]).trim();

reportFileName = ((String) objParms[1]).trim();

xmlDocument = (Document) objParms[2];

HashMap formParms = (HashMap) objParms[3];

 

long start = System.currentTimeMillis();

java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("ss.SSS");

 

reportFileName = FormTypeMappingCache.getInstance().getMapping(reportFileName,formParms);

formParms.put("JASPER_FILE_PATH",JASPER_REPORTS_FOLDER);

 

if (inputType.equalsIgnoreCase("xml"))

{

recordPath = RecordPathMappingCache.getInstance().getMapping(reportFileName);

CWXmlDataSource jrxmlds = new CWXmlDataSource(xmlDocument,recordPath);

 

long start2 = System.currentTimeMillis();

 

print = JasperFillManager.fillReport(

JASPER_REPORTS_FOLDER+reportFileName+".jasper",

formParms,

jrxmlds);

 

long elapsedTimeMillis = System.currentTimeMillis()-start2;

System.out.println("==> Time spent filling form with data was " + format.format(new Date(elapsedTimeMillis)) + " seconds");

}

else if (inputType.equalsIgnoreCase("db"))

{

jdbcConnection = connectDS();

 

long start2 = System.currentTimeMillis();

 

print = JasperFillManager.fillReport(

JASPER_REPORTS_FOLDER+reportFileName+".jasper",

formParms,

jdbcConnection);

 

long elapsedTimeMillis = System.currentTimeMillis()-start2;

System.out.println("==> Time spent filling form with data was " + format.format(new Date(elapsedTimeMillis)) + " seconds");

}

 

JRHtmlExporter exporter = new JRHtmlExporter();

 

HashMap imagesMap = new HashMap();

 

request.getSession().setAttribute("IMAGES_MAP", imagesMap);

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);

exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER,"<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body>");

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

String serverName = request.getServerName();

String serverPort = String.valueOf(request.getServerPort());

if (serverPort != null && serverPort.trim().length() > 0)

serverName = serverName + ":" + serverPort + "/";

String servletPath = "jenasys/servlet/";

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getScheme()+"://"+serverName+servletPath+"net.sf.jasperreports.j2ee.servlets.ImageServlet?image=");

//exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getScheme()+"://"+CDCProperties.getWebserverName()+CDCProperties.getAbsServletPath()+"net.sf.jasperreports.j2ee.servlets.ImageServlet?image=");

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

 

exporter.exportReport();

}

catch (JRException e)

{

out.println("<html>");

out.println("<head>");

out.println("<title>JasperReports Error</title>");

//out.println("<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">");

out.println("</head>");

 

out.println("<body bgcolor="white">");

 

out.println("<span class="bnew">JasperReports encountered this error :</span>");

out.println("<pre>");

 

e.printStackTrace(out);

 

out.println("</pre>");

 

out.println("</body>");

out.println("</html>");

throw e;

}

catch (Exception e)

{

e.printStackTrace();

throw e;

}

catch (Throwable te)

{

te.printStackTrace();

}

finally

{

if (jdbcConnection != null)

jdbcConnection.close();

}

}

 

Has anyone seen this before? I've attached a screen shot of my report. size=400]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/ImageServletBug.GIF

 

Post edited by: toltsch, at: 2006/12/14 21:12

 

Post edited by: toltsch, at: 2006/12/14 21:17

Post edited by: toltsch, at: 2006/12/14 21:31

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