Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP and iReports without database connection

 
Leonardo Betancourt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Leonardo Betancourt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic