This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "getWriter()" Watch "getWriter()" New topic
Author

getWriter()

gurusamy sengodan
Ranch Hand

Joined: Oct 13, 2005
Posts: 41
Hi,
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.

pascal
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
 
Consider Paul's rocket mass heater.
 
subject: getWriter()
 
Similar Threads
setContentType
servlet porting problem
Doubt on RequestDispatcher
setContentType and getOutputStream
Mistake in Head First Servlets & JSP