File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes getWriter() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "getWriter()" Watch "getWriter()" New topic


gurusamy sengodan
Ranch Hand

Joined: Oct 13, 2005
Posts: 41
I have written two methods. Name it as A(),B().
In A() Method i am calling getWriter()
In B() Method I am calling getOutputStream().

But i got the IllegalStateException saying that,
Cannot call getOutputStream() after getWriter().

Both are required for me.
I should not change the A() Method which is written by somebody and all are using the same i eman A().
But i need getOutputStream() in My method i mean B().

Please tell me how to avoid this problem.

Thanks in Advance
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
For your next posts: You should give some more information on your environment, the technologies and so on. Describe what and why you want to do (e.g. why you do not wan't/can't to use the getWriter() method) and then post it in the correct forum (there is a Servlet forum). In the most cases some code excerpts and the Exception Stacktrace are intersting too....

IllegalStateException saying that,
Cannot call getOutputStream() after getWriter().

There is nothing you can do about it.
If you check out the API then you'll find that this is documented and expected behaviour:

java.lang.IllegalStateException - if the getOutputStream method has already been called for this response object

You can only call either of the two methods.

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Writer can be user to send character data and stream can be used to send binary data.You can do both these operations using the outputstream.For binary data use outputstreams as it is and while sending character data ; convert the character to bytes (using the appropriate character set)and then flush that into the stream.In this way you can have functionalities of both by only using outputstream.

Rahul Bhattacharjee
LinkedIn - Blog
subject: getWriter()
It's not a secret anymore!