• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nguyen cuong
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:
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java 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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic