Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writer or Stream already obtained.  RSS feed

 
Bharat Ramchandani
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error at some points in my websites.. any idea what this pertains to??
Cannot forward. Writer or Stream already obtained.
any insight would be helpful.
rgds
brat.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are two slightly different (although related) issues.
The fisrt is the 'cannot forward'.
There are other ways to create this, but it is usually caused by an exception occuring after the response has been comitted. The response is comitted once the output buffer has filled and data has been sent to the user. ie you've started sending this page, it's too late to decide to send something else.
Some people think it's acceptable to increase the size of the buffer until the problem goes away, but it is actually much better to fix the problem rather than hide it.
The second part is the 'Writer or Stream already obtained'. From a javax.servlet.ServletResponse instance you can obtain either a PrintWriter or a ServletOutputStream. Not both. If you obtain one and then attemt to obtain the other, you get an exception.
What does this mean to you: my guess is you have a JSP or servlet that obtains a ServletOutputStream to return binary data. During the course of your data output, but after more than 8k has been sent, and exception is being thrown. The container catches this exception and tries to forward to the error handling page. While doing so it attempts to get a PrintWriter to output the page, but since the ServletOutputStream has already been obtained, it fails to complete the 'forward' operation and just falls over.
Just a guess based on what you've said, but it sounds right to me...
 
Bharat Ramchandani
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey DOM,
Thanks a lot for your reply, Atleast now I know "where" to look for "what",
Appreciate the help...think I have understood the problem with my website now.
rgds
brat.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!