Série da semana: Primeiros passos no React

Veja mais

Relatórios Ireport com java

02/03/2016

1

Preciso imprimir dois relatórios no meu projeto:

***** INDEX ****
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Página de execução relatórios </title>
</head>
<body>
<form action="relatorio">

Param: <input type="text"/>

<input type="submit" value="Relatório 1"/>

</form>
<form action="lista">

Param: <input type="text"/>

<input type="submit" value="Relatório 2"/>

</form>

</body>

</html>

Quando executo:

http://localhost:8080/Impressao/relatorio?
Executa o Relatório1. OK

http://localhost:8080/Impressao/lista?
Não executa o Relatório2.

Gera a Execption:

HTTP Status 404 - /Impressao/lista

type Status report

message /Impressao/lista

description The requested resource is not available.


*****RelatorioServlet***** (Relatorio1)
package br.edu.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.edu.conexao.ConexaoUtil;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import br.edu.conexao.ConexaoUtil;
/**
* Servlet implementation class RelatorioServlet
*/
@WebServlet("/relatorio")
public class FolgaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String pathRelatorios = getServletContext().getRealPath("/relatorios/") + "\\";

Map parametros = new HashMap<>();
parametros.put("SUBREPORT_DIR", pathRelatorios + "\\");

try {
JasperPrint jasperPrint = JasperFillManager
.fillReport(pathRelatorios + "report_subreport.jasper", parametros, ConexaoUtil.getConexao());

JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

} catch (ClassNotFoundException | JRException | SQLException e) {
e.printStackTrace();
}
}
}


*** ListaServlet**** (Relatorio2)
package br.edu.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.edu.conexao.ConexaoUtil;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

/**
* Servlet implementation class ListaServlet
*/
@WebServlet("/lista")
public class ListaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String pathRelatorios = getServletContext().getRealPath("/relatorios/") + "\\";

Map parametros = new HashMap<>();
parametros.put("SUBREPORT_DIR", pathRelatorios + "\\");

try {
JasperPrint jasperPrint = JasperFillManager
.fillReport(pathRelatorios + "report_folga.jasper", parametros, ConexaoUtil.getConexao());

JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

} catch (ClassNotFoundException | JRException | SQLException e) {
e.printStackTrace();
}
}
}
Responder