Jump to content
Changes to the Jaspersoft community edition download ×

Jasper Report + Jsp/Servlet


sk_shailesh

Recommended Posts

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi,

Check out the following code. It's a .jsp file in my web application, from this file i'm calling my report. If any queries feel free to revert back.

 

 

<%@ page import="java.io.*" %>

<%@ page import="java.sql.*" %>

<%@ page import="java.util.*" %>

<%@ page import="peoplewarejava.*"%>

<%@ page import="net.sf.jasperreports.engine.*" %>

<%@ page import="net.sf.jasperreports.engine.xml.JRXmlLoader"%>

<%@ page import="net.sf.jasperreports.engine.design.JasperDesign"%>

<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %>

<%@ page import="net.sf.jasperreports.view.*"%>

<%@ page import="net.sf.jasperreports.engine.util.*" %>

<%@ page import="net.sf.jasperreports.engine.export.*" %>

<%

JasperDesign jasperDesign= JasperManager.loadXmlDesign(getServletContext().getRealPath("/")+"reports/BirthdayPie.jrxml");

JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

Map parameters = new HashMap();

parameters.put("ReportTitle", "Birth Day Pie Report");

parameters.put("sub",getServletContext().getRealPath("/"));

Class.forName("org.postgresql.Driver");

Connection con1 = DriverManager.getConnection("jdbc:postgresql://localhost:5432/peopleWARE","postgres","postgres");

byte[] bytes = JasperRunManager.runReportToPdf( jasperReport, parameters, con1);

response.setContentType("application/pdf");

response.setContentLength(bytes.length);

ServletOutputStream ouputStream = response.getOutputStream();

ouputStream.write(bytes, 0, bytes.length);

ouputStream.flush();

ouputStream.close();

%>

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...