I have learned that JasperViewer (default preview component of JasperReports) is a Swing component, so is there any way to convert or embed it in
If you know how to generate a report, you can easily do it inside a servlet and send the generated file to the client. Using a JWS application or an Applet would most likely mean that the report is generated client-side and that the raw data plus all the dependencies are also available to the client.
The code below assumes that you're generating a PDF file
public class ReportServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// initialize your report objects here
JasperReport jasperReport =
JasperPrint print =
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, resp.getOutputStream());
resp.setContentType("application/pdf");
exporter.exportReport();
} catch (Exception e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error generating report : " + e.getClass() + " " + e.getMessage());
}
}
You can extend the example above to support multiple export formats by setting the correct content type and using the matching JRXYZExporter (JRHtmlExporter, JExcelApiExporter,...)
If you need something more customizable, you might also want to look into Jasper Server