The moose likes JSP and the fly likes Writer or Stream already obtained. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Writer or Stream already obtained." Watch "Writer or Stream already obtained." New topic
Author

Writer or Stream already obtained.

Bharat Ramchandani
Greenhorn

Joined: Feb 09, 2003
Posts: 21
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

Joined: Mar 06, 2001
Posts: 13459

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


[ JavaRanch FAQ ][ Book Promotions ][ DbTamer ][ BumperStickers ][ JavaRanch Badges ]
Bharat Ramchandani
Greenhorn

Joined: Feb 09, 2003
Posts: 21
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.
 
 
subject: Writer or Stream already obtained.
 
Threads others viewed
Mapping servlets
Strange error
JspSmartUpload + getoutputStream()error
JSP: IllegalStateException problem
Export to excel
developer file tools