Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutputStream already obtained error

 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you obtaining the output stream in a JSP when it is already exposed to you in the out implicit variable?
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic