• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ImageServlet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sf.jasperreports.j2ee.servlets.ImageServlet的典型用法代码示例。如果您正苦于以下问题:Java ImageServlet类的具体用法?Java ImageServlet怎么用?Java ImageServlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImageServlet类属于net.sf.jasperreports.j2ee.servlets包,在下文中一共展示了ImageServlet类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getJasperImage

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的package包/类
/**
 * This methods wraps the Jasper image servlet to avoid having a separate
 * servlet mapping around. Note that the path to images are relative to the
 * reports path in this controller.
 */
@RequestMapping( value = "/jasperReports/img", method = RequestMethod.GET )
public void getJasperImage( @RequestParam String image,
    HttpServletRequest request, HttpServletResponse response ) throws Exception
{
    new ImageServlet().service( request, response );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:12,代码来源:ReportController.java


示例2: doHandleRequest

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的package包/类
@Override
protected ModelAndView doHandleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
	servlet.service(request, response);
	request.getSession().removeAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE);
	return null;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:7,代码来源:JasperreportsHtmlImageController.java


示例3: service

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的package包/类
@Override
public void service(
	HttpServletRequest request,
	HttpServletResponse response
	) throws IOException, ServletException
{
	ServletContext context = this.getServletConfig().getServletContext();

	response.setContentType("text/html");
	PrintWriter out = response.getWriter();

	try
	{
		File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper"));
		if (!reportFile.exists())
			throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");

		JasperReport jasperReport = (JasperReport)JRLoader.loadObjectFromFile(reportFile.getPath());
	
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("ReportTitle", "Address Report");
		parameters.put("BaseDir", reportFile.getParentFile());
					
		JasperPrint jasperPrint = 
			JasperFillManager.fillReport(
				jasperReport, 
				parameters, 
				new WebappDataSource()
				);
					
		HtmlExporter exporter = new HtmlExporter();
	
		request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
		
		exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
		SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(out);
		output.setImageHandler(new WebHtmlResourceHandler("image?image={0}"));
		exporter.setExporterOutput(output);
		
		exporter.exportReport();
	}
	catch (JRException e)
	{
		out.println("<html>");
		out.println("<head>");
		out.println("<title>JasperReports - Web Application Sample</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>");
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:63,代码来源:HtmlServlet.java


示例4: download

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的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;
     }
 }
 
开发者ID:dayse,项目名称:gesplan,代码行数:73,代码来源:RelatorioHtml.java


示例5: doPost

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的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);
	} 
 	}
 
开发者ID:dayse,项目名称:gesplan,代码行数:43,代码来源:GeraRelatorioEmHTML.java


示例6: processRequest

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的package包/类
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ReportingException if failed to handle report request
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
        ReportingException {

    String component = request.getParameter("component");
    String template = request.getParameter("template");
    String type = request.getParameter("type");
    String reportData = request.getParameter("reportDataSession");
    String downloadFileName = null;

    if (component == null || template == null || type == null || reportData == null) {
        throw new ReportingException("required one or more parameters missing (component ,template , reportType, reportData)");
    }

    if (type.equals("pdf")) {
        response.setContentType("application/pdf");
        downloadFileName = template + ".pdf";
    } else if (type.equals("excel")) {
        response.setContentType("application/vnd.ms-excel");
        downloadFileName = template + ".xls";
    } else if (type.equals("html")) {
        response.setContentType("text/html");

    } else {
        throw new ReportingException("requested report type can not be support");
    }
    if (downloadFileName != null) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
    }
    Object reportDataObject = request.getSession().getAttribute(reportData);
    if (reportDataObject == null) {
        throw new ReportingException("can't generate report , data unavailable in session ");
    }

    try {
        String serverURL = CarbonUIUtil.getServerURL(request.getSession().getServletContext(), request.getSession());
        ConfigurationContext configurationContext = (ConfigurationContext) request.getSession().getServletContext().
                getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

        ReportResourceSupplierClient resourceSupplierClient = new ReportResourceSupplierClient(cookie,
                serverURL, configurationContext);

        String reportResource = resourceSupplierClient.getReportResources(component, template);
        JRDataSource jrDataSource = new BeanCollectionReportData().getReportDataSource(reportDataObject);
        JasperPrintProvider jasperPrintProvider = new JasperPrintProvider();
        JasperPrint jasperPrint = jasperPrintProvider.createJasperPrint(jrDataSource ,reportResource, new ReportParamMap[0]);
        request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);
        ReportStream reportStream = new ReportStream();
        ByteArrayOutputStream outputStream =  reportStream.getReportStream(jasperPrint,type);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        try{
        outputStream.writeTo(servletOutputStream);
        outputStream.flush();
        }finally {
            outputStream.close();
            servletOutputStream.close();
        }

    } catch (Exception e) {
        String msg = "Error occurred handling " + template + "report request from " + component;
        log(msg);
        throw new ReportingException(msg, e);
    }
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:72,代码来源:BeanCollectionReportServlet.java


示例7: processRequest

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String type = request.getParameter("reportType");
    String typeSecond = request.getParameter("reportTypeSecond");
    String dataSessionVar = request.getParameter("reportDataSession");
    String component = request.getParameter("component");
    String template = request.getParameter("template");
    String generateType;
    String downloadFileName = null;



    if (type == null) {
        type = " ";
    } else {
        typeSecond = " ";
    }

    if (type.equals("pdf") || typeSecond.equals("pdf")) {
        generateType = "pdf";
        response.setContentType("application/pdf");
        downloadFileName = template + ".pdf";
    } else if (type.equals("excel") || typeSecond.equals("excel")) {
        generateType = "excel";
        response.setContentType("application/vnd.ms-excel");
        downloadFileName = template + ".xsl";
    } else if (type.equals("html") || typeSecond.equals("html")) {
        generateType = "html";
        response.setContentType("text/html");


    } else {
        throw new ReportingException("requested report type can not be support");
    }
    if (downloadFileName != null) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
    }
    Object reportDataObject = request.getSession().getAttribute(dataSessionVar);
    if (reportDataObject == null) {
        throw new ReportingException("can't generate report , data unavailable in session ");
    }
    try {
        String serverURL = CarbonUIUtil.getServerURL(request.getSession().getServletContext(), request.getSession());
        ConfigurationContext configurationContext = (ConfigurationContext) request.getSession().getServletContext().
                getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

        ReportResourceSupplierClient resourceSupplierClient = new ReportResourceSupplierClient(cookie,
                serverURL, configurationContext);

        String reportResource = resourceSupplierClient.getReportResources(component, template);
        JRDataSource jrDataSource = new BeanCollectionReportData().getReportDataSource(reportDataObject);
        JasperPrintProvider jasperPrintProvider = new JasperPrintProvider();
        JasperPrint jasperPrint = jasperPrintProvider.createJasperPrint(jrDataSource ,reportResource, new ReportParamMap[0]);
        request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);
        ReportStream reportStream = new ReportStream();
        ByteArrayOutputStream outputStream =  reportStream.getReportStream(jasperPrint,generateType);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        try{
        outputStream.writeTo(servletOutputStream);
        outputStream.flush();
        }finally {
            outputStream.close();
            servletOutputStream.close();
        }

    } catch (Exception e) {
        String msg = "Error occurred handling " + template + "report request from " + component;
        log(msg);
        throw e;
    }
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:74,代码来源:GraphGenerateServlet.java


示例8: exportReportToHtmlStream

import net.sf.jasperreports.j2ee.servlets.ImageServlet; //导入依赖的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;
}
 
开发者ID:thingtrack,项目名称:konekti,代码行数:29,代码来源:ReportManagerServiceImpl.java



注:本文中的net.sf.jasperreports.j2ee.servlets.ImageServlet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IndexedRegion类代码示例发布时间:2022-05-22
下一篇:
Java MockMvcBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap