Я создал отчет с помощью jaspersoft, и теперь мне нужна функция в java для связи между отчетом и частью angularjs
для создания PDF-файла с некоторыми данными из моей базы данных postgresql
@RequestMapping(value = "/generatePDF", method = RequestMethod.GET)
public @ResponseBody void generatePDF(@RequestParam Long idContrat, HttpServletResponse response) throws SQLException,ClassNotFoundException,JRException {
Connection conn = null;
Contrat contrat=contratRepo.findOne(idContrat);
try {
String dbURL = "jdbc:postgresql://localhost/interim";
String user = "postgres";
String pass = "root";
conn = DriverManager.getConnection(dbURL, user, pass);
BufferedInputStream jasperStream = (BufferedInputStream) this.getClass().getResourceAsStream("/contrat.jrxml");
JasperDesign design = JRXmlLoader.load(jasperStream);
JRDesignQuery newQuery = new JRDesignQuery();
String sql = "SELECT interim.contrat.con_num_contrat,\r\n" +
" interim.contrat.con_date_contrat,\r\n" +
" interim.contrat.con_justification,\r\n" +
" interim.contrat.con_lieu_travail,\r\n" +
" interim.contrat.con_date_debut_travail,\r\n" +
" interim.contrat.con_date_fin_travail,\r\n" +
" interim.contrat.con_date_debut_amenag,\r\n" +
" interim.contrat.con_date_fin_amenag,\r\n" +
" interim.contrat.con_salaire_ref,\r\n" +
" interim.contrat.con_salaire_horaire,\r\n" +
" interim.contrat.con_nbr_heure_hebdo,\r\n" +
" interim.interimaire.int_type_interimaire,\r\n" +
" interim.interimaire.int_type_cadre,\r\n" +
" interim.interimaire.int_nom,\r\n" +
" interim.interimaire.int_prenom,\r\n" +
" interim.interimaire.int_ville,\r\n" +
" interim.interimaire.int_code_postal,\r\n" +
" interim.interimaire.int_autre_adresse,\r\n" +
" interim.interimaire.int_nom_voie,\r\n" +
" interim.interimaire.int_num_voie,\r\n" +
" interim.interimaire.int_date_naissance,\r\n" +
" interim.interimaire.int_lieu_naissance,\r\n" +
" interim.interimaire.int_num_sec_sociale,\r\n" +
" interim.interimaire.int_num_carte,\r\n" +
" interim.interimaire.int_date_expiration,\r\n" +
" interim.interimaire.int_type_carte,\r\n" +
" interim.client.clt_type_client,\r\n" +
" interim.client.clt_raison_sociale,\r\n" +
" interim.client.clt_commercial,\r\n" +
" interim.client.clt_nom_voie,\r\n" +
" interim.client.clt_num_voie,\r\n" +
" interim.client.clt_code_postal,\r\n" +
" interim.client.clt_ville,\r\n" +
" interim.client.clt_zone,\r\n" +
" interim.client.clt_siret,\r\n" +
" interim.client.clt_ape,\r\n" +
" interim.agence.ape,\r\n" +
" interim.agence.fax,\r\n" +
" interim.agence.libelle,\r\n" +
" interim.agence.siret,\r\n" +
" interim.agence.telephone,\r\n" +
" interim.entreprise.code_postale,\r\n" +
" interim.entreprise.fax,\r\n" +
" interim.entreprise.libelle,\r\n" +
" interim.entreprise.nom_voie,\r\n" +
" interim.entreprise.numero,\r\n" +
" interim.entreprise.siren,\r\n" +
" interim.entreprise.telephone1,\r\n" +
" interim.entreprise.telephone2,\r\n" +
" interim.entreprise.ville,\r\n" +
" interim.entreprise.photo,\r\n" +
" interim.entreprise.formjuridique,\r\n" +
" interim.entreprise.type_voie,\r\n" +
" interim.nationnalite.nat_libelle,\r\n" +
" interim.qualification.qua_libelle,\r\n" +
" interim.facteur_penibilite.fac_libelle,\r\n" +
" interim.contrat.con_essai,\r\n" +
" interim.contrat.con_paye\r\n" +
"FROM interim.facteur_penibilite_contrat\r\n" +
" INNER JOIN interim.contrat ON \r\n" +
" interim.facteur_penibilite_contrat.con_id = interim.contrat.id \r\n" +
" INNER JOIN interim.interimaire ON \r\n" +
" interim.contrat.id_interimaire = interim.interimaire.id \r\n" +
" INNER JOIN interim.client ON \r\n" +
" interim.contrat.id_client = interim.client.id \r\n" +
" INNER JOIN interim.agence ON \r\n" +
" interim.contrat.id_agence = interim.agence.id \r\n" +
" AND interim.client.id_agence = interim.agence.id \r\n" +
" AND interim.interimaire.id_agence = interim.agence.id \r\n" +
" AND interim.client.id_agence = interim.agence.id \r\n" +
" INNER JOIN interim.entreprise ON \r\n" +
" interim.agence.id_entreprise = interim.entreprise.id \r\n" +
" INNER JOIN interim.nationnalite ON \r\n" +
" interim.interimaire.nat_id = interim.nationnalite.nat_id \r\n" +
" INNER JOIN interim.qualification ON \r\n" +
" interim.contrat.qua_id = interim.qualification.qua_id \r\n" +
" INNER JOIN interim.facteur_penibilite ON \r\n" +
" interim.facteur_penibilite_contrat.fac_id = interim.facteur_penibilite.fac_id\r\n" +
" WHERE interim.contrat.id =$P{id_contrat}";
newQuery.setText(sql);
design.setQuery(newQuery);
JasperReport report = JasperCompileManager.compileReport(design);
Map<String, Object> parameterMap = new HashMap<>();
//List<Contrat> contrats = contratRepo.findAll();
//JRDataSource jrDataSource = new JRBeanCollectionDataSource(contrats, false);
parameterMap.put("id_contrat", idContrat);
JasperPrint jasperPrint = JasperFillManager.fillReport(report,parameterMap, conn);
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline: filename = contrat.pdf");
final ServletOutputStream outputStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
} catch (JRException e)
{
e.printStackTrace();
logger.info("test file contrat.jrxml");
} catch (IOException e){
e.printStackTrace();
}
}
у меня ошибка 500 на моем сервере angular.js: 11756 GET http://localhost:8080/generatePDF?idContrat=4 500 (Erreur Interne de Servlet)