I am new programming in java and I have encountered a small problem, I am generating a pdf report taking as datasource
a JSON file, but I have not managed to pass the JSON to JasperFillManager.fillReport
to generate the pdf, if I charge it through a bd, it works, but with the JSON NO. This is the code I have:
// clase que carga json
public class JsonParsing implements Connection {
public static void main(String[] args) {
try {
JSONParser jsonParser = new JSONParser();
File file = new File("web\WEB-INF\empleados.json");
Object object = jsonParser.parse(new FileReader(file));
//System.out.println(object);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
// servlet que genera reporte.
public class ServletReport extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ParseException, JRException {
try{
response.setContentType("application/pdf");
JsonParsing metodo = new JsonParsing();
ServletOutputStream out = response.getOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(getServletContext().getRealPath("WEB-INF/principal.jasper"), new HashMap<String, Object>(), metodo);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
}
catch(IOException e){
}
}
}
Thank you.