Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getWriter()

 
gurusamy sengodan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic