Win a copy of Succeeding with AI 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Error: getOutputStream() has already been called for this reponse

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all, I'm a newbie, so I lack experience on solving some errors, I really appreciate if you help me to solve this.
I got a error

I tried to implement iReport into my web project. I used Netbean to create the project.
I have 2 classes: ConnectionManager.java and JaperReportWrapper.java
The first one is used to connect with the database, I can handle it.
The second one is used to connect the database with iReport and some method to compile a JRXML file and export into a PDF file.
I also created a jsp file: CustomerInvoicesReports.jsp
Here is this:

Maybe the errors occurred at this line

Because when I deleted it, the error disappeared.
Any body help me, please. I really appreciate this.
PS: The JasperReportWrapper.java is following:
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to mix text (the automatic variable "out", which is used for the HTML start, and even the line breaks after your JSP directives) with binary (response.getOutputStream()). That's not going to work. Instead try JRExporterParameter.OUTPUT_WRITER combined with that automatic variable "out":
 
nguyen cuong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It really works. The error has disappeared. But my purpose is to export a PDF file from a iReport file(*.RXML), instead the screen would show a PDF file, it's appeared a prompt

 
Rob Spoor
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to create a PDF file? Then drop most of that page. That is generating HTML; check the content type.

What you would need to do to generate PDF from a JSP is this:
1) set the proper content type
2) do not use any text, including text between JSP directives and/or other JSP tags
3) use response.getOutputStream() again

Step 2 is very important, as without it the JSP file will use the default JspWriter instead of OutputStream, and you will get your error again.


Or, the simpler approach, use a servlet instead of JSP.
 
nguyen cuong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be more specific? A sample will be better for me, I even don't know how to do what you told I'm so poor
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic