outputStream already obtained

Joined
May 17, 2007
Messages
1
Reaction score
0
Hi,


I know this topic has been handled in this forum before because I tried to implement the solution.

I work with WSAD 5.1 jsp to jsp calling for a pdf document.

First time i call it it fails with "File not found exception."
Next time onwards the pdf downloads and opens fine but I get the error mesage:

"OutputStream already obtained"


Can anyone Please direct me as to how I can avoid this:


this is part of the code:

String CONTENT_TYPE = "application/ETS_pdf";
response.reset();
// response.setHeader("pragma", "no-cache");
response.setHeader("pragma", "");
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.setDateHeader("Expires", 0);
session = request.getSession(false);
.............................................
.......................................

// ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = response.getOutputStream();
try {

// create a writer that listens to the document
// and directs a PDF-stream to output

PdfWriter.getInstance(document, os);

............................
..........................

document.close();

response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition:", "attachment;filename=" + fileName);
response.setHeader("Content-transfer-encoding:", "binary");
response.setHeader("Cache-Control:", "post-check=0, pre-check=0");

InputStream is = null;
try
{
int i = 0;
is = new FileInputStream(os.toString());
while((i=is.read()) != -1)
{
os.write(i);
}
} catch (Exception e)
{}
finally
{
if(os != null)
{
os.flush();
os.close();
}
if(is != null)
{
is.close();
}
}




This is a snippet of the output:


WARNING:.Cannot.set.header..Response.already.committed. in bundle com.ibm.ejs.resources.seriousMessages
.........................
[5/17/07 12:50:38:461 EDT] 22c822c8 WebGroup E SRVE0026E: [Servlet Error]-[OutputStream already obtained]: java.lang.IllegalStateException: OutputStream already obtained
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java:511)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:202)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:193)
at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:246)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:197)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:255) .........................."


I get this everytime.

Please advise

J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top