• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

getWriter()

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic