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
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