本文整理汇总了Java中net.sf.jasperreports.engine.export.JRHtmlExporter.exportReport方法的典型用法代码示例。如果您正苦于以下问题:Java JRHtmlExporter.exportReport方法的具体用法?Java JRHtmlExporter.exportReport怎么用?Java JRHtmlExporter.exportReport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.jasperreports.engine.export.JRHtmlExporter
的用法示例。
在下文中一共展示了JRHtmlExporter.exportReport方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("text/html;charset=UTF-8");
JRHtmlExporter exporter=new JRHtmlExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
req.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
String path=req.getContextPath();
if(path.endsWith("/")){
path+="dorado/bdf2/jasperreports/html.image";
}else{
path+="/dorado/bdf2/jasperreports/html.image";
}
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,path+"?image=");
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例2: exportToHTML
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
private void exportToHTML() {
log.debug("exporting to HTML");
htmlExporter = new JRHtmlExporter();
setExportParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IMAGES_URI,"servlets/image?image=");
setExportParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
htmlExporter.setParameters(getExportParameters());
try {
start = System.currentTimeMillis();
htmlExporter.exportReport();
log.info("export running time (msec): "
+ (System.currentTimeMillis() - start));
} catch (JRException jre) {
jre.printStackTrace();
}
}
示例3: download
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
/**
* metodo responsavel pelo preenchimento do relatorio, a partir do arquivo jasper compilado, do nome do arquivo html,
* e considerando os dados sob a forma de List e os par�metros
*
* @param nomeArquivo
* @param streamRelatorio
* @param parametros
* @param dados
* @throws RelatorioException
*/
public void download(String nomeArquivo, InputStream streamRelatorio, Map parametros, List dados) throws RelatorioException {
String caminhoRelatorio = caminhoRelatorioHTML + nomeArquivo;
System.out.println("CAMINHO RELAT�RIO: " + caminhoRelatorio);
File relatorio = new File(caminhoRelatorio);
byte[] buffer = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getResponse();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\"" + nomeArquivo + "\"");
if (parametros == null) {
parametros = new HashMap();
}
//Neste ponto, a nossa lista preenchida com o modelo � entregue ao Jasper, que cria um DataSource com ela
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(dados);
//Aqui � onde ocorre de fato o preenchimento do relat�rio, com os par�metros e DataSource passados
JasperPrint impressao = JasperFillManager.fillReport(streamRelatorio, parametros, dataSource);
//Ponto onde o relat�rio com os dados montados � exportado para o formato HTML
JasperExportManager.exportReportToHtmlFile(impressao, caminhoRelatorio);
FileInputStream fis = new FileInputStream(relatorio);
OutputStream os = response.getOutputStream();
response.setContentType("text/html");
JRHtmlExporter htmlExporter = new JRHtmlExporter();
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, impressao);
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, impressao);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, os);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/gesplan/image?image=");
htmlExporter.exportReport();
int read = 0;
buffer = new byte[1024];
while ((read = fis.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
os.flush();
os.close();
fis.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (Throwable ex) {
ex.printStackTrace();
throw new RelatorioException(ex);
} finally {
buffer = null;
}
}
示例4: doPost
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String nomeDoRelatorio = (String)request.getAttribute("nomeDoRelatorio");
System.out.println(">>>>>>>>>>>>>>>Nome do relatorio="+nomeDoRelatorio);
List lista = (List)request.getAttribute("lista");
HashMap<String, String> parametros = (HashMap<String, String>)request.getAttribute("parametros");
ServletContext context = this.getServletContext();
String nomeDoArquivoCompilado = context.getRealPath(nomeDoRelatorio);
System.out.println(">>>>>>>>>>>>>>>>>>>> nomeDoArquivoCompilado="+nomeDoArquivoCompilado);
File arquivo = new File(nomeDoArquivoCompilado);
PrintWriter printWriter = response.getWriter();
try
{ JasperReport relatorioCompilado = (JasperReport) JRLoader.loadObject(arquivo);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(lista);
JasperPrint impressao = JasperFillManager.fillReport(relatorioCompilado, parametros, ds);
JRHtmlExporter htmlExporter = new JRHtmlExporter();
response.setContentType("text/html");
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, impressao);
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, impressao);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, printWriter);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/gesplan/image?image=");
htmlExporter.exportReport();
}
catch(JRException e)
{ e.printStackTrace(printWriter);
}
}
示例5: exportReportToHtmlStream
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
@Override
public ByteArrayOutputStream exportReportToHtmlStream(WebApplicationContext context, Organization organization, String code, Map<String,Object> parameters, String destFileName) throws Exception {
JasperPrint jasperPrint = executeReport(organization, code, parameters);
// create the stream out report
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// get context uri
String uri = context.getHttpSession().getServletContext().getContextPath();
JRHtmlExporter exporter = new JRHtmlExporter();
String random = "" + Math.random() * 1000.0;
random = random.replace('.', '0').replace(',', '0');
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, uri + "/image?r=" + random + "&image=");
context.getHttpSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
outputStream.flush();
outputStream.close();
return outputStream;
}