cezar_apulchro Posted January 30, 2019 Share Posted January 30, 2019 Hi, trying to create a report using jasperstudio I created an new servlet, but my problem still the same. I have find this servlet in Youtube site but I'm getting an erro. Above my Servlet: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package com.itc_systems_web_mw0;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;import javax.servlet.RequestDispatcher;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.JasperRunManager;import net.sf.jasperreports.engine.util.JRLoader;/** * * @author Cezar Apulchro */public class ListAgendaEletro_S05 extends HttpServlet{ public Connection conectar; /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { geraRelatorio(request, response); } catch (JRException ex) { Logger.getLogger(ListAgendaEletro_S05.class.getName()).log(Level.SEVERE, null, ex); } } protected void geraRelatorio(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JRException { String erro = ""; String dataexame = null; String pathJasper = getServletContext().getRealPath("/WEB-INF/Reports/ListEletro_P63.jasper"); File arquivo = new File(pathJasper); HashMap<String, Object> parameters = new HashMap<String, Object>(); byte[] bytes = null; ServletContext contexto = getServletContext(); dataexame = request.getParameter("dtaagenda"); parameters.put("paramData", dataexame); try { JasperReport relatorio = (JasperReport) JRLoader.loadObjectFromFile( contexto.getRealPath(pathJasper)); bytes = JasperRunManager.runReportToPdf(relatorio, parameters, conectar); } catch (JRException e) { erro = e.getMessage(); System.out.println("Erro: " + erro); } finally { if (bytes != null) { response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream outStream = response.getOutputStream(); outStream.write(bytes); outStream.flush(); outStream.close(); } else { RequestDispatcher reqDisp = request.getRequestDispatcher("Agenda_Eletro_WM01.jsp"); request.setAttribute("Erro: ", erro); reqDisp.forward(request, response); } } } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold>}And the error: java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRLoader.loadObjectFromFile(Ljava/lang/String;)Ljava/lang/Object; at com.itc_systems_web_mw0.ListAgendaEletro_S05.geraRelatorio(ListAgendaEletro_S05.java:104) at com.itc_systems_web_mw0.ListAgendaEletro_S05.doPost(ListAgendaEletro_S05.java:79) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:748)Environment: IDE: Netbeans 8.2 Server: Glassfish 4.1.1 Repository Maven Thanks in advance. Cezar Apulchro Link to comment Share on other sites More sharing options...
cezar_apulchro Posted January 30, 2019 Author Share Posted January 30, 2019 Sorry,I wrong title question.My problem is: "java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRLoader.loadObjectFromFile(Ljava/lang/String;)Ljava/lang/Object;" Link to comment Share on other sites More sharing options...
hozawa Posted January 31, 2019 Share Posted January 31, 2019 > JasperReport relatorio = (JasperReport) JRLoader.loadObjectFromFile(> contexto.getRealPath(pathJasper));The problem is with the above statement.JRLoader() requires a File, InputStream, JasperReportsContext, or a URL.http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/util/JRLoader.htmlcontextto is a ServletContext and .getRealPath() returns a String.https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html If you want to pass a String, the method to use is loadObjectFromFile(filename) Link to comment Share on other sites More sharing options...
cezar_apulchro Posted January 31, 2019 Author Share Posted January 31, 2019 when was occured this problem I find your answer in this link https://community.jaspersoft.com/questions/960276/netsfjasperreportsengineutiljrloaderloadobject I changed to loadObjectFromFile but the problem still the same. Link to comment Share on other sites More sharing options...
cezar_apulchro Posted January 31, 2019 Author Share Posted January 31, 2019 i do this servlet following this video: Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now