本文整理汇总了Java中net.sf.jasperreports.engine.export.JRHtmlExporter.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java JRHtmlExporter.setParameter方法的具体用法?Java JRHtmlExporter.setParameter怎么用?Java JRHtmlExporter.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.jasperreports.engine.export.JRHtmlExporter
的用法示例。
在下文中一共展示了JRHtmlExporter.setParameter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getHTML
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
public static byte[] getHTML(StorageService storageService, JasperPrint jasperPrint)
throws JRException {
byte[] content = null;
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
JRHtmlExporter exporter = new JRHtmlExporter();
// Jasper Images will be stored to reports home directory
// so to be accesed from HTML
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, storageService.getSettings().getReportsHome());
exporter.setParameter(JRHtmlExporterParameter.SIZE_UNIT, "px");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "./");
content = getBytes(exporter, baos, jasperPrint);
} finally {
if (baos != null) {
try {
baos.flush();
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return content;
}
示例3: getHtmlExporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
protected JRHtmlExporter getHtmlExporter() {
JRHtmlExporter exporter = new JRHtmlExporter();
String random = "" + Math.random() * 1000.0;
random = random.replace('.', '0').replace(',', '0');
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, Utils.getWebContextPath(EnterpriseApplication.getInstance()) + "/image?r=" + random + "&image=");
return exporter;
}
示例4: getHtmlExporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入方法依赖的package包/类
protected JRHtmlExporter getHtmlExporter() {
JRHtmlExporter exporter = new JRHtmlExporter();
String random = "" + Math.random() * 1000.0;
random = random.replace('.', '0').replace(',', '0');
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, getWebContextPath() + "/image?r=" + random + "&image=");
return exporter;
}
示例5: 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;
}
}
示例6: 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);
}
}
示例7: 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;
}