Olá,
porque com o codigo abaixo não gera o aqruivo psf em uma pagina jsp …
Se alguém puder me ajudar …
agradeceria …
abs
public class R01Action implements Action {
EntityManager manager = null;
private EntityManagerFactory emf = null;
public R01Action(){
}
public String execute(HttpServletRequest request,HttpServletResponse response) throws SQLException {
emf = Persistence.createEntityManagerFactory("ims");
manager = emf.createEntityManager();
Session session = (Session) manager.getDelegate();
Connection con = session.connection();
try{
File reportFile = new File("C:\\desenvolvimento\\Workspaces\\Relatorio\\reports\\ImsGrupo001.jasper");
Map parameters = new HashMap();
parameters.put("tipo_grupo", Long.valueOf(request.getParameter("tipo_grupo")));
byte[] bytes = JasperRunManager.runReportToPdf("C:\\desenvolvimento\\Workspaces\\Relatorio\\reports\\ImsGrupo001.jasper",parameters,con);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
} catch (JRException e) {
e.printStackTrace();
}finally{
con.close();
manager.close();
emf.close();
}
return "/pagina/r01e.jsp";
}
-- pagina criada r01e.jsp para sair o relatório em pdf
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
<h1>Relatório</h1>
</body>
</html>
---------------
-- ServLet criado pra gerenciar qual pagina chamar
public class ServletAction extends HttpServlet {
RequestDispatcher rd=null;
public ServletAction() {
// TODO Auto-generated constructor stub
}
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
PrintWriter out = resp.getWriter();
String acao = req.getParameter("acao");
System.out.println("acao="+acao);
Class clazz = Class.forName("br.com..relatorio.action." + acao + "Action");
Action action = (Action) clazz.newInstance();
String Mapping = action.execute(req,resp);
rd = req.getRequestDispatcher(Mapping);
rd.forward(req,resp);
}catch(Exception e){
req.setAttribute("erro", e);
rd = req.getRequestDispatcher("/pagina/erro.jsp");
rd.forward(req,resp);
System.out.println("Erro="+e);
}
}
}