我不明白为什么我的代码没有一直运行。我正在打开jasper报告,但是对于前4个打开时间,报告被缓存或代码没有执行(新StreamResource中的代码没有执行前4次)。新的StreamResource.StreamSource()只在5次运行,为什么?前4次,我得到了旧的,缓存的,临时的或我的事件不知道什么pdf文件与旧的帕拉姆。
也许有人知道这个问题?
public static void open(final String fileName, final HashMap<String, Object> data ) {
mylog.pl("@@@ Param's print @ open Report: Filename:" + fileName);
try {
Iterator<?> i = data.keySet().iterator();
while (i.hasNext()) {
String id = i.next().toString();
String value = (data.get(id) != null) ? data.get(id).toString() : "null";
mylog.pl(" id: " + id + " value: " + value);
}
} catch (Exception e) {
e.printStackTrace();
mylog.pl(e.getMessage());
}
StreamResource.StreamSource source = null;
source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
InputStream reportStream = null;
try {
reportStream = new BufferedInputStream(new FileInputStream(PATH + fileName + JASPER));
b = JasperRunManager.runReportToPdf(reportStream, data, new JREmptyDataSource());
} catch (JRException ex) {
ex.printStackTrace();
mylog.pl("Err @ JR" + ex.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
Utils.showMessage(SU.NOTFOUND);
return null;
}
return new ByteArrayInputStream(b);
}
};
StreamResource resource = null;
resource = new StreamResource(source, fileName + PDF);
resource.setMIMEType("application/pdf");
Page p = Page.getCurrent();
p.open(resource, "Report", false);
}发布于 2014-06-18 06:41:50
在这里is的答案
我一直使用resource.setCacheTime(0);,但真的需要resource.setCacheTime(1000);,因为
理论上,<= 0禁用缓存。在实践中,Chrome、Safari (显然还有IE)都忽略了<=0。
https://stackoverflow.com/questions/24262174
复制相似问题