Problema no servlet para impressão de relatorio em impressora matricial

0 respostas
M

Oi pessoal, estou precisando de uma ajuda.

Tenho um relatório criado no ireport e eu precisava imprimir esse relatorio em uma impressora matricial, só que não estou conseguindo. Olhei em alguns foruns, fiz umas tentativas mas o relatorio fica em branco.
O servlet que fiz é o seguinte´: Será que alguém pode me dar uma ajuda?
Estou começando agora a desenvolver em Java, então to meio perdida…

Obrigada!!!

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
      ServletOutputStream servletOutputStream = 
			response.getOutputStream();

      String caminho = "/relatorio/";
      String relatorio = caminho+"Teste.jasper";
      InputStream reportStream = getServletConfig().
              getServletContext().
              getResourceAsStream(relatorio);
     
      Connection connection = null;
    
     ServletContext context = getServletContext();
     
      try {
          //cria a conexão com o banco de dados
          Class.forName("com.mysql.jdbc.Driver");
          String db = "jdbc:mysql://localhost:3306/alpktreinament";
          connection = (Connection) DriverManager.getConnection(db,"root",null);

        JasperPrint impressao = JasperFillManager.fillReport(relatorio, new HashMap(), connection);

      File file = new File("/relatorio/Teste.txt");  
        JRTextExporter exporter = new JRTextExporter();   
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, impressao);   
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file);   
        exporter.setParameter( JRTextExporterParameter.CHARACTER_WIDTH, new Integer( 8 ) );   
        exporter.setParameter( JRTextExporterParameter.CHARACTER_HEIGHT, new Integer( 13 ) );   
        exporter.setParameter( JRTextExporterParameter.PAGE_WIDTH, new Integer( 110 ) );   
        exporter.setParameter( JRTextExporterParameter.PAGE_HEIGHT, new Integer( 34 ) );   
        exporter.exportReport();  

        JasperViewer view = new JasperViewer(impressao);   
        view.setVisible(true);  

      }
Criado 11 de fevereiro de 2009
Respostas 0
Participantes 1