wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes JSP and iReports without database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JSP and iReports without database connection" Watch "JSP and iReports without database connection" New topic
Author

JSP and iReports without database connection

Leonardo Betancourt
Greenhorn

Joined: Aug 08, 2011
Posts: 2
Hello,

I would like to know how to show a report without an a database connection. My source code is... but not work

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>

<%
File reportFile = new File(application.getRealPath("reports/rep.jasper"));

Map parameters = new HashMap();
parameters.put("Nombre", "Leonardo");
parameters.put("Apellidos", "Betancourt Teran");
parameters.put("email", "leobeta@gmail.com");

byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath (), parameters , JREmptyDataSource());

response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);

ouputStream.flush();
ouputStream.close();

%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Welcome to the Ranch.

Step 1 is to move this code out of a JSP and into a servlet. Using a JSP for producing anything other than text content is liable to cause no end of troubles.

And, the practice of putting Java code in a JSP has been considered a poor practice for almost 10 years now.

I'm still not sure what database connections have to do with your question through. Just saying "it doesn't work" gives us no useful information with which to help you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Leonardo Betancourt
Greenhorn

Joined: Aug 08, 2011
Posts: 2
Well, my code doesn't work. So how can I show a report made by iReport on a web app based on JSP?
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
It looks like you are putting your data in the report parameters and you are sending in an empty datasource. Your data should be in the datasource.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Leonardo Betancourt wrote:Well, my code doesn't work.

Please read ItDoesntWorkIsUseless. Without details, it's impossible to help.

So how can I show a report made by iReport on a web app based on JSP?

There's no such thing as a JSP-based app. If you've got JSP capabilities, you've got servlet capabilities. JSP is for creating text responses, not binary.

Please read this article to understand how JSP operates.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP and iReports without database connection