Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in explanation

 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all....i am new to javaranch...i found this on javabeat.com

what does this mean?
It is possible to produce only one type of output (either character-based or binary-based)
...but when i run a similar example on netebans i dont get any error
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've not provided enough information to help you. The statement says so because you can only call either response.getOutputStream (binary output stream) or response.getWriter (text output stream) on a response object. So you can say that we can write either binary or text (character) based response. If you show us the example which you say is working, we'll be able to help you further...
 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i want to know the reason for this...i have closed the stream of printwriter before opening for the output stream...

i only get mosby as the output and an error....why?
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:you can only call either response.getOutputStream (binary output stream) or response.getWriter (text output stream) on a response object.
 
neil keefe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coincidentally I just came from another topic that contained a similar ambiguity about the word "only":
A JAR file can contain classes from only a single package

(From the SCJP 6 prep book. The book claimed this was a wrong statement. But of course a JAR file can contain classes from only a single package.)

In this case:
you can only call either response.getOutputStream (binary output stream) or response.getWriter (text output stream) on a response object.

Example of the ambiguity:
You can only get into the house either through the back door, or through the basement window.

My two burgler friends are happy to discover that entry by the back door does not preclude entry also through the basement window.

Unambiguous to say, perhaps, that you can only call one of either .getOutputStream or .getWriter.

 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what if i enter the house from the front door to find demons and then come outside only to enter from the backdoor to save my love...means what if i oen outputstream...then close it and then open the writer?
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ted mosby wrote:but what if i enter the house from the front door to find demons and then come outside only to enter from the backdoor to save my love...means what if i oen outputstream...then close it and then open the writer?

What happened when you tried it?? When you close the OutputStream or Writer, the connection with the client is lost, so you cannot call the other one after closing the first one...
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ted.
but what if i enter the house from the front door to find demons and then come outside only to enter from the backdoor to save my love...means what if i oen outputstream...then close it and then open the writer?


As 'Ankit' said, if we close OutputStream or Writer, connection between client and server is lost. If you find demons when you enter through front door, clear the demons first and forward the resource(using RequestDispatcher's forward() method) to save your love.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic