File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes OutputStream already obtained error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "OutputStream already obtained error" Watch "OutputStream already obtained error" New topic
Author

OutputStream already obtained error

Subha Rangu
Greenhorn

Joined: Jul 23, 2004
Posts: 29
Hi,
I was trying to use OutputStream object in a JSP page.
[Servlet Error]-[OutputStream already obtained]: java.lang.IllegalStateException: OutputStream already obtained

I have done opstream.flush() and opstream.close() before and after the usage resp.

Please advise me what has to be done.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Why are you obtaining the output stream in a JSP when it is already exposed to you in the out implicit variable?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Subha Rangu
Greenhorn

Joined: Jul 23, 2004
Posts: 29
I have to show up an image on a JSP which I get from a method which a Java API returns in byte[] format. That is the reason why I am using outputStream.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

A few points:

1) Again, the output stream is already available as 'out'.

2) You can't just emit image data into the middle of a page, you must use an <img> tag.

3) The <img> tag should reference a servlet to return the dynamic image data. JSP is a very poor technology choice for returning non-text data.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Bubly,

From Tony Morris's response in this thread, you need to ignore the second line.

However, as Bear suggests, this may not achieve what you want. The example in the thread describes how to send a TIFF image to the browser from a Servlet.

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutputStream already obtained error
 
Similar Threads
PDF File Streaming in a JSP
OutputStream already obtained
Error 500: OutputStream already obtained
Exception with displaying image
Mapping servlets