Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JSP and iReports without database connection

 
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();

%>
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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?
 
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
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
Trust God, but always tether your camel... to this tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!